Does getCurrentPosition() use GPS navigation? - javascript

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.

Related

Can not retrieve location share on smartphone browser

I try to take my location by using the share location html5 geolocation on the browser, when run in PC browser it appears a notif to allow access share location, while when I try on my smartphone browser chrome / firefox it does not work ... so my question..
whether when share location it only take Lat / Lot according from my IP ..
When share location why is not accurate, is taking the location of my card provider phone.
whether to use the GPS feature on our smartphone to take the location through the browser.

HTML5 geolocation vs Google Maps Geolocation api

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.

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.

Firefox 3.5+ doesn't fire errorCallback on getCurrentPosition()

The problem is that if the user denies access to location data, the google map is never initialized.
For Example: http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html
When it asks for permission, say not now. The map will be grey.
What can I do to initialize the map no matter what?
I decided to just set a default center point on the map so that if I get a more specific position, I zoom in there, if not I leave it alone.
Hopefully Mozilla fixes this soon, since the bug has been around nearly a year.
Use a server-side script to do IP address geolocation. This will yield a location in the same country at least. Use the IP address's location as default if the user does not permit geolocation in the browser.
An example web service providing IP geolocation is http://www.geobytes.com/iplocator.htm Google will find many more.

Categories

Resources