HTML5 geolocation will not work in Firefox, Chrome and Chromium

I am trying to use the HTML5 geolocation API; but I have problems to get it working with Firefox Chrome and Chromium:

init(); function init() {; // Get the current location getPosition(); } function getPosition() { navigator.geolocation.getCurrentPosition(success, fail,{ enableHighAccuracy:true, timeout:10000, maximumAge:Infinity }); } function success(position) { alert("Your latitude: " + position.coords.latitude + "longitude: " + position.coords.longitude); } function fail(e) { alert("Your position cannot be found"+e.code+" => "+e.message); } 

IE9 and Safari work flawlessly; but:

  • Firefox (v13 and V14) has error code 3 (timeout)
  • Chrome and Chromium (v20 and v21) have error code 2 with the message "Network location provider" on the page https://maps.googleapis.com/maps/api/browserlocation/json?browser=googlechrome&sensor=true ': The answer was deformed .

I have a new installation of Chrome (installed today on Windows XP, no extensions), and I enabled geolocation in the browser.

You can try: http://jsfiddle.net/mhj82/38/

Is there a solution for it to work in all browsers that support geolocation?

+3
source share
3 answers

Did you read this? http://code.google.com/p/chromium/issues/detail?id=41001

At the end of the stream, they conclude that in order to work in Chrome, geolocation must be performed on a device with a working wifi adapter.

Was Wi-Fi enabled on your computer?

(dunno for firefox)

0
source

I need to wait until the document is loaded to make it work in chrome

 jQuery().ready(function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition.... } }); 
0
source

Try this on a Chrome desktop and mobile devices.

 if (navigator.geolocation) { var latitude = null; var longitude = null; navigator.geolocation.getCurrentPosition(function (position) { latitude = position.coords.latitude; longitude = position.coords.longitude; }); } else { alert("Geolocation API is not supported in your browser"); }; 
0
source

Source: https://habr.com/ru/post/956858/


All Articles