HTML5 geolocation vs Google Maps Geolocation api - javascript

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?

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.

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

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.

Related

How to make javascript Geolocation API work consistently?

I'm working on a project where the user's location is needed. The implementation seems to be working correctly, the user gets a prompt to allow sharing their location and the coordinates are received.
The problem is that those coordinates seem to wildly change based on the device or browser. Three different browsers in the same device provide 3 different coordinates, and not just with my code, the same happens when testing with other sites that provide geolocation like https://my-current-location.com/
Does this mean that the browsers Geolocation API can't be trusted? Is there a better way of obtaining a user's location that's more reliable?
I've tried working with server-side location (IP) and the results were also as bad, at least for the part of the world where this needs to work.

HTML5: get device altitude

In my HTML5 page I would like to retrieve the altitude of the device (I'm testing on my Nexus 5 with Chrome mobile).
As mentioned in HTML5 Geolocation Altitude, the altitude returned by the Geolocation API is always null.
I've read that some native Android apps use different approaches such as pressure sensor (when available). Is it somehow possible in HTML5? Do you have other suggestions?
Accessing barometer information
Sadly as of 2015 it's not possible to access barometer information in a native browser environment. A lot of work has been done on writing sensor API specifications, but as barometers are quite a rare hardware feature still they have not been receiving a lot of attention.
It is however possible to bundle your web application in Cordova and use the barometer plugin for android to access the barometer from your code. This however means that the user has to install your application and this would only work Android.
Using GPS information after all
For the large majority of applications where you need altitude information there is only one possible altitude per coordinate pair (this is for example not true if you wish to determine the level you're at in a building, but current GPS altitude information isn't precise enough for that normally either way). In those cases you can request the GPS location and simply request the altitude from a service with a surface database. Two such services are the Google Elevation API (entire world) or the NED Point Query Service (US only?).

Desktop web browser how accurate is navigator.geolocation

I was wondering for my website, how accurate is the GeoLocation attribute of the navigator object in desktop web browsers? I guess on a mobile web browser this simply activates a GPS device so therefore is based on GPS signal at that time. However what about on a desktop? Does it have some means of determining its location and to what accuracy?
According to the spec:
Under the interface section:
The Geolocation object is used by scripts to programmatically determine the location information associated with the hosting device. The location information is acquired by applying a user-agent specific algorithm, creating a Position object, and populating that object with appropriate data accordingly.
Under the requirements section
6.2.8 The Geolocation API must be agnostic to the underlying sources of location information.
TL;DR: Depends on the browser's implementation. This could mean that it could use anything available on the device. It may even be possible to have "Mobile Provider" and "GPS" on a PC, since there are devices like Nokia Booklet 3G that has GPS and can be inserted a SIM.

How can javascript request location from android

I am developing mobile web page. I want send from this page request to my native mobile app (for example android app, and android app should send me current location of user.
Thanks in advance !
Look for the accepted language header on the server side. Or via js:
navigator.language
See this question: JavaScript for detecting browser language preference
It looks like you'll want to use the geolocation API.
The geolocation API will work on phone browsers that support that API. It may be worth checking the compatibility of the handsets you are targeting.
Also, just bringing these alternatives to your attention, however, they are restricted to certain operators and regions.
BlueVia location API available on O2 and Telefonica networks using their REST API https://bluevia.com/en/page/tech.APIs.LocationAPI
AT&T location API available using their REST API http://developer.att.com/developer/apiDetailPage.jsp?passedItemId=10100355
Just so you know about these, the geolocation API is most likely the best option for you though.

Does getCurrentPosition() use GPS navigation?

If I use navigator.geolocation.getCurrentPosition() in any web page and visit it using web browser of any mobile device with GPS, will it use GPS navigation?
And how it will determine location if device has no GPS?
The Geolocation API is agnostic of the underlying location information sources and therefore it is up to the browser (and device) to determine how the geolocation data is determined.
See here for more details on how Firefox gets the geo location information from Google, http://code.google.com/p/gears/wiki/GeolocationAPI
Short answer is: they keep a database with the location of all wifi hotspots (most likely collected by the same cars that take streetview footage) and uses that information to provide location data.

Categories

Resources