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

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.

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.

Increase Accuracy IE 11 Geolocation

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.

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