# Retrieving GPS location / geolocation via browser (for mobile use)

**URL:** <https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534>\
**Category:** Developing Nodes\
**Created:** [25 November 2020 23:05 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534 "2020-11-25T23:05:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyhulse](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeremyhulse/32/32605_2.png) [@jeremyhulse](https://discourse.nodered.org/u/jeremyhulse)\
**Post date:** [25 November 2020 23:05 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/1 "2020-11-25T23:05:46Z")

</div>

I am a design master's student and I'm making a prototype service that plays back geo-tagged audio clips that are nearby to the user, based on the user's live location. I am interested in using Node-RED as a prototyping tool to build a basic browser application for use with both iOS and Android mobile devices.

In order to make this work I need to get the user's live GPS location, ideally every 10-20 seconds. I tried installing the [node-red-contrib-gpsd](https://flows.nodered.org/node/node-red-contrib-gpsd) GPSd node, but for some reason it wouldn't install in my palette (not sure why). From my understanding, it's also not quite right for my application.

I am therefore looking to use existing Geolocation APIs to build a new Node and would like to ask if anyone can help, or has done this before? Some of the APIs I came across and was considering using are the [HTML Geolocation API](https://www.w3schools.com/html/html5_geolocation.asp), [Mozilla's Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API) and the [W3C Geolocation API](https://w3c.github.io/geolocation-api/).

As you may be able to tell, I am pretty new to Node-RED, so any help would be greatly appreciated! 🙏

Many thanks,  
Jeremy

---

<div class="post-metadata">

**Author:** ![xunjoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xunjoy/32/32620_2.png) [@xunjoy](https://discourse.nodered.org/u/xunjoy)\
**Post date:** [25 November 2020 23:09 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/2 "2020-11-25T23:09:51Z")

</div>

Would also like to know!!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 November 2020 12:03 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/3 "2020-11-26T12:03:40Z")

</div>

Hi Jeremy, welcome to the forum!

Where is node-red going to be running? i.e. on what device and where will that be located? The iOS or Andriod device will have to send it's location to the device running Node-RED

One other issue you may run into is that that node ( node-red-contrib-gpsd) hasn't been updated in 3 1/2 years and may not work at all anymore. And if it did, I wluod imagine it would be picking up the location of the device that node--red is running on, not the phone the user is using.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 November 2020 12:32 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/4 "2020-11-26T12:32:59Z")

</div>

Could this be used to get it from the browser? [https://www.w3schools.com/html/html5\_geolocation.asp](https://www.w3schools.com/html/html5_geolocation.asp) as suggested earlier?

---

<div class="post-metadata">

**Author:** ![ibmrcruicks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ibmrcruicks/32/83099_2.png) [@ibmrcruicks](https://discourse.nodered.org/u/ibmrcruicks)\
**Post date:** [26 November 2020 14:05 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/5 "2020-11-26T14:05:38Z")

</div>

Have you had a look at using [https://developer.mozilla.org/en-US/docs/Web/API/Geolocation\_API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API) ? @Colin's suggestion makes use of this in the mobile device browser, which you can send back to a host/cloud-based node-red instance via web-sockets, or a pub/sub protocol like mqtt.  
If you want to build a new node, check out node-red-contrib-web-components as a basis -- it might help to make it straightforward to wrap the browser geolocation data into server-side node-red events

---

<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:** [26 November 2020 15:54 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/6 "2020-11-26T15:54:28Z")

</div>

You can perhaps find some "ideas" in [this](https://discourse.nodered.org/t/experimenting-with-html-geolocation-api/16709) discussion. Note that I have never published that node...  
Bart

---

<div class="post-metadata">

**Author:** ![jeremyhulse](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeremyhulse/32/32605_2.png) [@jeremyhulse](https://discourse.nodered.org/u/jeremyhulse)\
**Post date:** [27 November 2020 16:39 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/7 "2020-11-27T16:39:41Z")

</div>

Hi All, thanks for all your feedback!

@zenofmud we plan to use Node-RED to build a browser-based web app that is linked directly to the cloud-based server, so most of the processing will take place on the server side. We've been in touch with @ibmrcruicks and will be trying the web-socket approach he suggested 🙂

@BartButenaers interesting, thanks for sharing!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 January 2021 16:39 UTC](https://discourse.nodered.org/t/retrieving-gps-location-geolocation-via-browser-for-mobile-use/36534/8 "2021-01-26T16:39:41Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
