Increase Accuracy IE 11 Geolocation - javascript

I have a Google Map (v3) on a website. When a user hits the page, I am reading the geolocation from it´s browser (if it´s supported):
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {enableHighAccuracy: true, timeout: timeOut, maximumAge: maximumAge })
The function is working, but not always as expected. In Google Chrome it´s working perfectly - the getCurrentPosition function is returning a coordinate object with latitude and longitude as floating points (decimals). Curiously it´s different in IE11. It´s also returning the coordinate object - but here are both latitude and longitude in integers, which means, that the accuracy is very bad, and not really showing the right position on the map.
Is this a bug? And does anyone know if it´s possible to fix this?
Thank you!

Different browsers use different geolocation service providers to get an estimate of your location and that could explain why you're seeing different results with Google Maps.
Google Chrome similarly uses Google Location Services. The default geolocation service provider of Firefox is Google Location Services as well. Safari uses Skyhook Wireless's service.
Searching on the web, I could not find which specific geolocation service provider IE makes use of but the different results you see between browsers can be attributed to the quality of data provided by the geolocation service provider. So my guess is, you have to wait for the precision of the geolocation calculation in IE to improve as I haven't seen any documented way to change the geolocation service provider that a browser uses. Alternatively, see if Bing Maps works well in IE or try using a commercial IP-based Geolocation detector service like Maxmind to detect coordinates.

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.

Why is chrome desktop getting my Location wrong?

Im building an app that requires location. Im serving my app locally via apache and have permitted chrome to give my virtual host access to location despite being served without ssl. My coordinates are coming out wrong as (6.5243793 3.3792057). Thats completely in another state on another part of my country. When I visit https://www.gps-coordinates.net/my-location, it gives the same location. But on firefox, https://www.gps-coordinates.net/my-location is giving me a more accurate location. On chrome mobile, im also getting a correct location Here is my code snippet
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var lat = position.coords.latitude,
long = position.coords.longitude;
initMap(lat,long);
// logging to console to find out why the map location is incorrect
console.log(lat+" "+long)
});
}
Can someone tell me whats going on, or better yet how to find out the exact location, probably through google maps api?
Chrome on mobile uses the GPS in your phone.
Chrome on desktop uses a service that estimates your location based on your IP address. This database is imprecise and often out of date. Firefox uses a different service, which works in the same way, but where your particular IP has a more accurate record.

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?).

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