HTML5 geolocation won't work in Firefox, Chrome and Chromium
Asked Answered
Q

3

3

I'm trying to use the HTML5 geolocation API; but I have problems to make it work on 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);
}

In IE9 and Safari it works flawlessly; but :

  • in Firefox (v13 and V14) there is an error code 3 (timeout)
  • in Chrome and Chromium (v20 and v21) there is and error code 2 with the message "Network location provider at 'https://maps.googleapis.com/maps/api/browserlocation/json?browser=googlechrome&sensor=true' : Response was malformed."

I have a fresh install of Chrome (installed today on windows XP, no extensions) and I have authorized the geolocation in the browser.

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

Is there a solution to make it work on all browser supporting geolocation ?

Quinsy answered 7/8, 2012 at 8:16 Comment(3)
Works fine for me on Chrome v21 on MacAntifreeze
I've asked some friends to test this jsfiddle, and it's seems to work for some of them, but that's not explaining why it doesn't work here :(Quinsy
Did you find out what the problem was? I'm having the same issue... @QuinsyConformal
D
0

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

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

Was wifi enabled on your computer ?

(dunno for firefox)

Dorthadorthea answered 7/8, 2012 at 9:37 Comment(1)
Yes, I've tested in Chrome on Mac OS X with a WiFi adapter, and doesn't work.Quinsy
F
0

I have to wait until the document is loaded to get it work in chrome

jQuery().ready(function() {
   if (navigator.geolocation) { 
        navigator.geolocation.getCurrentPosition....
    }
});
Faustena answered 7/2, 2013 at 16:40 Comment(0)
W
0

Try this tested in chrome desktop and mobile

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");
};
Wheel answered 18/3, 2014 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.