# Experimenting with HTML Geolocation API

**URL:** <https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709>\
**Category:** Dashboard\
**Created:** [14 October 2019 21:32 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709 "2019-10-14T21:32:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [14 October 2019 21:32 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/1 "2019-10-14T21:32:17Z")

</div>

Hi folks,

Recently some forum members helped me controlling my garage door openers via Node-RED, which works fine at the moment. However using the dashboard for this purpose is currently a bit impractical: I need to grab my smartphone, open the dashboard app, navigate to the button to open the ports. So the whole process is a bit slow ...

So the wife asked: is it possible to have the dashboard open a popup dialog automatically (to ask whether the garage door should be opened), as soon as we approach our house at e.g. 200 meters. Although there are nice tutorials (e.g. to use the OwnTracks app) to determine your location, I would like to create a custom UI node because:

- I always try to avoid having to install multiple tools to get the job done.
- I would like to have it fully integrated into Node-RED to be able to control everything.
- I just like to develop fun stuff ...

So the last two hours I quickly wrote a **node-red-contrib-ui-geolocation** node:

- Since it is fully experimental, it is not on Github available yet.
- It is based on the [HTML5 GeoLocation API](https://www.w3schools.com/html/html5_geolocation.asp).
- Would like to have in the future multiple trigger types (to specify when a message needs to be send to my Node-RED flow):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/786c80ead3dd802617b968429daa01f4956ad5e9.png)
- Currently it shows some ugly output in the dashboard:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bc909bcad797c624a6a30f7d95245f2bd125265c.png)
- And it sends an output message already to my Node-RED flow:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a2d9d9f75eb85e38bb8fca87256e4ded4d1e7e02.png)

_But I don't know at the moment whether it is useful anyway to continue the development of this node..._  
_Because this would mean my Node-RED dashboard should be active all the time on my smartphone._  
_So there might be issues with power consumption, connection lost, gsm in sleep mode, and so on ..._

Would like to know how I can use the dashboard to make things like this possible?

Thanks !!!  
Bart

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 October 2019 21:48 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/2 "2019-10-14T21:48:53Z")

</div>

As you spotted already, as this is running browser side it has to keep running and consuming power. Dedicated apps like owntracks run in the background nicely and can be set to report at intervals as well.  
Feel free to try using dashboard and do the experiment if you have time....  
(Or maybe just ask siri,Alexa etc to turn on the heating)

---

<div class="post-metadata">

**Author:** ![paulohlp](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@paulohlp](https://discourse.nodered.org/u/paulohlp)\
**Post date:** [14 October 2019 22:59 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/3 "2019-10-14T22:59:00Z")

</div>

I would like to suggest a different approach.

What about a esp32 or similar board inside the car?  
When it finds your wifi send a signal to open the gate?

You may put a led that alerts that is connected.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [15 October 2019 02:50 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/4 "2019-10-15T02:50:56Z")

</div>

> [@paulohlp](#):
>
> What about a esp32 or similar board inside the car?

As an experiment I tried this a while ago. Unfortunately, by the time a signal is confirmed and a connection is made I had been sitting waiting for some seconds (longer than it would take to manually press the remote). Went back to a manual system.

Some things are just not worth the hassle of trying to automate with iot, imo.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [15 October 2019 05:35 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/5 "2019-10-15T05:35:26Z")

</div>

For a completely different approach, have you thought about using a phone app such as Telegram (or pushcuts if you happen to be on iOS as it fits perfectly for this use case) and get an incoming message/notification send to this app with a link inside connecting to your node-red install that offers the open/close aspect?

So keep all the logic handling inside node-red as much as possible, then trigger an outgoing message to the device. On iOS, especially iOS 13, you can utilise location triggers for this, such as arriving at/leaving location, without too much overhead. However I don’t know a good equivalent for other platforms. I have my own tracker with me if I need to 🙂

Another option that hasn’t been mentioned yet: a beacon on a keychain, with periodic scanning done by a local device that warns node-red when a specific beacon comes in range or goes out of range.

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [15 October 2019 06:22 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/6 "2019-10-15T06:22:03Z")

</div>

Another possibility, although not 100% reliable, might be something based on [WUDS (Wifi User Detection System)](https://www.lanmaster53.com/2014/10/02/wifi-user-detection-system/). It means having Wifi scanning enabled on your phone, but you can then check the MAC address and use that to signal your garage doors.

There are a few implementations around, mostly based on Raspberry Pi and Python, but I did a quick hack into C++ for an ESP8266, and it works pretty well.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 October 2019 07:46 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/7 "2019-10-15T07:46:43Z")

</div>

I suppose if it's the phone doing the scanning there is nothing to prevent you detecting someone else's access point a bit away from your house to give you extra time :-)... though of course you need to ensure it knows that you are arriving and not leaving ...

---

<div class="post-metadata">

**Author:** ![paulohlp](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@paulohlp](https://discourse.nodered.org/u/paulohlp)\
**Post date:** [15 October 2019 12:43 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/8 "2019-10-15T12:43:44Z")

</div>

> [@Bobo](#):
>
> Some things are just not worth the hassle of trying to automate with iot, imo.

[BartButenaers](https://discourse.nodered.org/u/BartButenaers)

What about Iftt?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 October 2019 13:59 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/9 "2019-10-15T13:59:09Z")

</div>

I have a Dragino [Lora GPS tracker](https://www.dragino.com/products/lora/item/142-lgt-92.html), the LGT-92-LI version, updates every minute (can be changed) to The Things Network, drop it in the car. Lasts about 10 days. Unless you drive with 120km/h to your home, it could be useful. Coverage in BE is ok-ish depending on where you are. But yes, siri can do it automagically.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [15 October 2019 14:48 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/10 "2019-10-15T14:48:07Z")

</div>

> [@dceejay](#):
>
> As you spotted already, as this is running browser side it has to keep running and consuming power.

@dceejay: Tja thought so... But hoped there was perhaps a solution using background worker or whatever.  
But seems I will have to abandon this mechanism. What a pitty...

> [@dceejay](#):
>
> Or maybe just ask siri,Alexa etc to turn on the heating

Well that might be an interesting idea. Then I don't have to try finding any buttons to press. Will need to start playing with this ... Thanks!

> [@paulohlp](#):
>
> What about a esp32 or similar board inside the car?

@paulohlp: that could indeed be a solution. Similar to the proposals of @molesworth and @bakman2 . But the advantage of an app is that everybody in our familly always have their smartphone with them. E.g. when we go for a walk or ... we just need our smart phone and we will be able to open the garage door. But good proposal!

> [@afelix](#):
>
> message/notification send to this app with a link inside connecting to your node-red install that offers the open/close aspect?

@afelix: yes but I need to make sure that the garage door is opening automatically. I just want to get a 'proposal' to open it. For example when I accidentally pass by my house with the car, I don't want the doors to open automatically ...

> [@paulohlp](#):
>
> What about Iftt?

@paulohlp: IFTT could indeed warn my Node-RED flow automatically, but then my Node-RED flow still cannot show a popup on my Smartphone (to let me choose whether I want to open the door or not). Or did I misunderstood your idea?

---

<div class="post-metadata">

**Author:** ![paulohlp](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@paulohlp](https://discourse.nodered.org/u/paulohlp)\
**Post date:** [15 October 2019 17:13 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/11 "2019-10-15T17:13:27Z")

</div>

> [@BartButenaers](#):
>
> Or did I misunderstood your idea?

Was I that forgot that you need a popup. To be honest I don´t know if Iftt has this option.

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [15 October 2019 17:36 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/12 "2019-10-15T17:36:33Z")

</div>

> [@BartButenaers](#):
>
> > [@paulohlp](#):
> >
> > What about a esp32 or similar board inside the car?
> 
> @paulohlp: that could indeed be a solution. Similar to the proposals of @molesworth and @bakman2 . But the advantage of an app is that everybody in our familly always have their smartphone with them. E.g. when we go for a walk or ... we just need our smart phone and we will be able to open the garage door. But good proposal!

The "WUDS" approach I mentioned has the device in your house, and it detects when a phone with WiFi scanning enabled comes close. It pretends to be a WiFi access point, and phones or other devices will send "probe" packets to get info.

In my version I white-list my own and friends and family's devices, and only raise an alert when an unknown device with a high signal strength is detected. (I also have a green-list for e.g. the postman, so I know if I'm likely to have mail when I get home 🙂)

For your application you'd do the opposite, and could trigger events when a family phone is detected - although as @dceejay mentioned, you'd need some logic to figure out whether it's someone arriving.

I'm now thinking about what I can do in my setup when a "friendly" device appears...

---

<div class="post-metadata">

**Author:** ![Alacritous](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Alacritous](https://discourse.nodered.org/u/Alacritous)\
**Post date:** [21 October 2019 00:28 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/13 "2019-10-21T00:28:41Z")

</div>

ESP-NOW would handle this. The handshaking for esp-now is milliseconds.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [21 October 2019 03:07 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/14 "2019-10-21T03:07:14Z")

</div>

> [@Alacritous](#):
>
> The handshaking for esp-now is milliseconds.

But more than that, the range seems to be triple that of normal wifi. Curious now to try it out.

Nice find, thanks.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 October 2019 06:10 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/15 "2019-10-21T06:10:21Z")

</div>

Most of the suggestions here suffer from a timing problem. Many of the ones for phones also suffer from a power problem. IFTTT only claims a time accuracy to 15 minutes. Telegram is better but is ocassionally delayed by maybe 10-20sec (a lot at 200m @ 2-30kph).

Also, you cannot really guarantee GPS either, especially on a phone since they will prefer to manage power over location accuracy. Best I've ever been able to do is a geofence of about 500m where we are. That might work for you but not really for us as we are in a dense urban area.

Owntracks would be best since you can also work out whether you are coming or going. Or maybe ESP-Now (I've not tried that).

---

<div class="post-metadata">

**Author:** ![marshall](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@marshall](https://discourse.nodered.org/u/marshall)\
**Post date:** [29 February 2020 19:12 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/16 "2020-02-29T19:12:58Z")

</div>

Hi Bart - I'm interested in the **node-red-contrib-ui-geolocation** I would like to use it to get my location from the UI so I can log the location for commissioning a device.

What you have shown in your post is ideal, is there any chance you could release the node please.

Thanks  
Marshall

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [29 February 2020 20:44 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/17 "2020-02-29T20:44:14Z")

</div>

Hello @marshall,  
The problem is that this node is **FAR** from complete:

- It uses lots of energy, so not ideal for a smartphone.
- Currently the dashboard needs to be open, otherwise I doesn't send any locations. Should run as a background worker in the browser somehow.
- ...

So unfortunately not much to publish...

---

<div class="post-metadata">

**Author:** ![marshall](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@marshall](https://discourse.nodered.org/u/marshall)\
**Post date:** [29 February 2020 20:47 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/18 "2020-02-29T20:47:57Z")

</div>

thanks for the quick reponse.

Do you have any tips on how to get the current location from the device, using a function or template node?

All I am really looking for is to click a button, and it returns the location. I actually don't want it to be dynamic.

Thanks for the pointers.

Regards  
Marshall

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [29 February 2020 20:52 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/19 "2020-02-29T20:52:45Z")

</div>

> [@marshall](#):
>
> how to get the current location from the device

In my first post above you can find the link to the Javascript Geolocation API. It is very easy, and indeed you can call it in a template node (if a button is clicked).

---

<div class="post-metadata">

**Author:** ![marshall](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@marshall](https://discourse.nodered.org/u/marshall)\
**Post date:** [29 February 2020 20:53 UTC](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709/20 "2020-02-29T20:53:31Z")

</div>

THanks, I'm too dumb to figure out how to it. I'll try a bit harder.,..

[Next page](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709.md?page=2)
