Jump to content

[FEATURE] Get current location from browser


clubstew

Recommended Posts

Modern browsers support (most of) HTML5 - even mobile browsers. It would be nice if Geocaching.com would use the Location API (http://www.w3.org/TR/geolocation-API/). It's simple to use and if the browser doesn't support is easy to filter out. As a simple example:

 

<button id="useCurrent" style="display: none">Current Location</button>
<script type="text/javascript">
(function()
 if (navigator.geolocation) {
   var btn = document.getElementById("useCurrent");
   if (btn) {
     btn.addEventListener("click", function() {
       var loc = document.getElementById("currentLocation"); // or whatever the location element is
       navigator.geolocation.getCurrentPosition(function(pos) { loc.value = pos.latitude + " " pos.longitude }); // overly simple example
     });
     btn.display = "block";
   }
 }
)();
</script>

Link to comment

Modern browsers support (most of) HTML5 - even mobile browsers. It would be nice if Geocaching.com would use the Location API (http://www.w3.org/TR/geolocation-API/). It's simple to use and if the browser doesn't support is easy to filter out. As a simple example:

 

<button id="useCurrent" style="display: none">Current Location</button>
<script type="text/javascript">
(function()
 if (navigator.geolocation) {
   var btn = document.getElementById("useCurrent");
   if (btn) {
     btn.addEventListener("click", function() {
       var loc = document.getElementById("currentLocation"); // or whatever the location element is
       navigator.geolocation.getCurrentPosition(function(pos) { loc.value = pos.latitude + " " pos.longitude }); // overly simple example
     });
     btn.display = "block";
   }
 }
)();
</script>

Link to comment

When I started caching in 2007 there used to be a static (or it might have been random) map on the home page show some caches.

This was changed in about 2008 (I'm guessing here) to use the user's location grabbed from the web browser but it was so inaccurate it was soon scrapped

 

For me it was about 100 miles out. Totally pointless :unsure:

 

 

Mark

Link to comment

I'm familiar with the HTML5 location API and, in fact, have used to for a service for locating computing resources around the university in which I work. I'm just curious as to what the use case would be for using the location from the browser. Assuming you could get a users general location from the browser, how would you use that information?

Link to comment

I'm familiar with the HTML5 location API and, in fact, have used to for a service for locating computing resources around the university in which I work. I'm just curious as to what the use case would be for using the location from the browser. Assuming you could get a users general location from the browser, how would you use that information?

 

I have my laptop/tablet with me and no dedicated app and I'm using the web site to find nearby caches. Frankly, with a dedicated AGPS chip (more common in tablets) and support in the web site, a dedicated app wouldn't really be necessary (and would stay up to date better). That's whole point of all the functionality added in HTML5 - reducing the need of proprietary thick client apps.

Link to comment

I'm familiar with the HTML5 location API and, in fact, have used to for a service for locating computing resources around the university in which I work. I'm just curious as to what the use case would be for using the location from the browser. Assuming you could get a users general location from the browser, how would you use that information?

 

I have my laptop/tablet with me and no dedicated app and I'm using the web site to find nearby caches. Frankly, with a dedicated AGPS chip (more common in tablets) and support in the web site, a dedicated app wouldn't really be necessary (and would stay up to date better). That's whole point of all the functionality added in HTML5 - reducing the need of proprietary thick client apps.

 

From what I've ready about AGPS, the use of cell tower triangulation or wifi location is only used for approximating a location for the initial satellite fix. Once the initial satellite fix is obtained the "assisted" part no longer applies.

 

I don't know enough about the internals of the location API, but my impression of the advantage of a native mobile app vs. a mobile web application (using HTML5) is that the former can talk directly to the native device hardware (GPS, Camera, the local "file system", etc.). Will the Location API attempt to use the native GPS if it's available? My assumption was that it only used cell phone triangulation and wifi info to provide lat/long coordinates. I could see how they could be used to produce a center point for a proximity search but I just don't think the lat/long coordinates would be accurate enough for actual caching. What could be interesting though would be to create a puzzle cache with a web page that used the location API and wifi positioning to navigate indoors. I've seen an application that used wifi positioning in a large library to help patrons navigate the stacks to find a book.

Link to comment

Modern browsers support (most of) HTML5 - even mobile browsers. It would be nice if Geocaching.com would use the Location API (http://www.w3.org/TR/geolocation-API/).

Erm, it does...

 

On the Geocaching Maps page, there is a "Find my location" button (crosshair icon) in the top-left of the map. It only appears if your browser supports the Geolocation API and if you have selected Leaflet rather than Google as your map preference (if you are a Premium Member). It's a bit of a gimmick on a desktop browser (as you're likely to be sat at your home location anyway), but it's much more useful on a mobile platform like a tablet.

 

How well it works depends on your browser and operating system. While you may have GPS hardware, your browser needs to be able to figure out how to connect to it. Mobile browsers tend to be good at that. If the browser can't figure out how to connect to GPS (a common Windows issue), it can still try by looking up your IP address (might be 100s of miles out) or the details of nearby cellphone or wifi signals (accuracy between several miles to 10s of meters).

 

Geocaching.com doesn't use the Geolocation API directly. It just uses the widget built into the Leaflet API. One problem with the way it does this is that it does not allow a long enough timeout to wake up the GPS hardware on my Android tablet and wait for the first fix (this is a GC.com flaw, not a problem with Leaflet). I've built a fix for this issue into my Geocaching Map Enhancements userscript. GME also goes one step further and has an option to continuously update the map location. If you're getting location data from GPS, this turns Geocaching Maps into a moving maps app!

 

There's no reason why Groundspeak couldn't add a similar function to the Google Maps view.  As Google Maps is default for Premium Members, it's a bit odd that you get fewer features!  It could also be used elsewhere on the website, so that e.g. listing pages show distance from your current location, or you could do a location-based search from the Hide&Seek page.  I might look at adding some of these features to a future version of GME...

Link to comment

I don't know enough about the internals of the location API, but my impression of the advantage of a native mobile app vs. a mobile web application (using HTML5) is that the former can talk directly to the native device hardware (GPS, Camera, the local "file system", etc.). Will the Location API attempt to use the native GPS if it's available?

 

 

The API just provides a standard method for a web page to get location information from a web browser. It's up to the browser to figure out what that location is the best it can. Browsers are native apps, so they can use whatever hardware the operating system made available (and various other methods of guessing).

 

Mobile operating systems tend to know about GPSrs, but whether their security model lets the browser get at the data is another matter. When I was writing widgets for a Nokia S60 platform, you couldn't get at GPS info through the web browser, you had to write a native app. However, I've tested the API using Firefox Mobile and Opera Mobile on an Asus Transformer TF101 (Android 4.0.3) and an HTC Desire (Android 2.2), using my GME script. In both cases, it worked fine with the internal GPS on the device and the result was perfectly adequate for geocaching.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...