HTML5 geolocation vs Google Maps Geolocation api
Asked Answered
W

3

28

I'm a bit confused as to why I would choose to use the limited access Google Maps Geolocation API over the free and (apparently) unlimited navigator.geolocation feature of HTML5?

As far as I can tell the only advantage of the Google version is it's increased support for browsers such as IE8. Am I missing something significant here? Or is there little difference?


On further investigation we noticed that when we used navigator.geolocation in Chrome it actually makes a call to the Google api to get the information (backed up by this answer from 6 years ago). So this begs the question, is it still limited? If so by how much in what period?

Wexford answered 4/3, 2016 at 15:15 Comment(0)
P
24

The Google Maps Geolocation API is an HTTP endpoint that accepts user-supplied JSON data about nearby Wifi networks and cell towers and produces an estimate of the user's location.

The HTML5 navigator.geolocation object supplies a browser API that does some set of operations and then produces an estimate of the user's location. From the W3C geolocation spec:

The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input.

The navigator.geolocation function may make use of any information available to the browser application, including any information from the device's GPS hardware, if it has any. Of course, it may also make use of any third-party Web APIs (including, possibly, the Google Maps Geolocation API) that can be reached. There is no specified required approach or inputs that must or must be used; the browser can do anything in its power to make a location estimate. It may do a better or worse job than Google's approach, depending on their particular implementations, or the browser may (as you suggest) actually directly use Google's API.

In short, Google's API is a way to ask, "Based on this cell and Wifi info, tell me where I am." The HTML5 API is a way to tell the browser, "You have access to the Internet and all the physical inputs available to my device; find out where I am, somehow."

I'm not surprised to learn that, if no GPS is present, the browser might outsource its geolocation work to a third-party service like Google. Browser vendors are generally interested in making browsers, not writing a robust service to solve the hard problem of transforming cell/Wifi data into location information. Furthermore, it requires a tremendous amount of geospatial data about the locations of various towers and Wifi SSIDs. It would bloat the browser to hold all the information locally, and any attempt for thevendor to host the information remotely would functionally be setting up a competitor to Google's already known-good service.

Politesse answered 4/3, 2016 at 15:34 Comment(5)
So, essentially, the advantage of the Google APi is that you know exactly how it is being implemented? Where as the HTML5 version is more ...vague.... in it's implementation but ultimately will return a reasonably valid result?Wexford
The HTML5 API could potentially make use of more (and more accurate) local physical sources, like GPS, or it could not, depending on brower implementation and hardware availability (i.e. does your device actually have a GPS?). It's difficult to say if this makes it "better" or "worse" that a Web API. The implementation could differ between browsers (and hardware availability), while Google will give you consistent browser-independent results, so that's something, too, I guess.Politesse
@Wexford I've added one more brief paragraph to the end: geolocation is a hard problem that vendors are not interested in solving, and it's a problem that requires a high volume of real-world spatial data about cell towsers and Wifi networks.Politesse
Is there a way to find out precision that is accuracy of the device's location? Say that device is in a building and it has enabled perms, turned on GPS, how accurate will be his location? Few meters?Gangboard
@Gangboard I think this would make a fine question of its own, but the short answer (for navigator.geolocation API) is that the coords object also has an accuracy property expressing the probable error of the coordinates in meters (so, a radius of how many meters the position may be off by).Politesse
M
7

The HTML5 API is going to trigger a modal popup to ask the user to give permission vs the Google Maps Geolocation API is going to bypass that. The methods themselves to gather location are very similar though the scope is there for HTML5 to go deeper depending how the browser implements it.

Example HTML5 - https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

Example Google Maps Geolocation - http://webkay.robinlinus.com/

Also Ref: https://developers.google.com/maps/articles/geolocation

  • Maps API might give you an option for an older browser that doesn't support HTML5 or of course a non-browser client (native etc)
  • Maps API will cost you $ after the free daily quota
  • HTML5 method should be prioritised over others in most cases
Middelburg answered 2/4, 2016 at 12:16 Comment(0)
A
1

I just want to mention that if this is all you need, then no, there is no reason to go with the paid Google service--the spec for that service is basically built into the browser at this point.

The Google Maps API comes with many more features than that, however--things like reverse geocoding, and the full visual tool featureset available with maps.

So yes, getting a user's lat/lon is 'free'--no need to pay for that feature by itself.

Alderete answered 1/3, 2021 at 12:30 Comment(2)
Hi Kyle, I'm bit late for the party. Can you tell me how accurate is Google Maps API vs browser (suppose the latest browser and all perms are enabled)? My use case is that if I have my mobile web app and its is being used by 5 users in a room (which is in a shopping mal) would it be able to get precise locations of all 5 users, within couple of metersGangboard
I can't tell you for sure, no, but I can tell you that in general GPS won't work in a mall and you'll be getting best guess from wifi data. What you're asking is basically a no-go unless you are able to write manual wifi triangulation code natively--which would be insane, and even then, definitely not going to happen in a browser.Alderete

© 2022 - 2024 — McMap. All rights reserved.