0

I'm having trouble of using the geolocation on my website on android phones.

I've got the following javascript code:

if (navigator.geolocation) {
    console.log("true"); //gets logged
    navigator.geolocation.getCurrentPosition(sucess, error, {timeout: 5000});
} 

It always times out with error.code 3 and error.message "Timeout expired".

This happens on version 2.x and 4.x of Android.

Please keep in mind that this is NOT in combination with phonegap or similar. It's a plain old website that's opened in a browser.

The code works fine on iPhones.

Is there sth. wrong with my code or is it a problem on the android side?

2
  • may be 5 seconds is not enough Commented Mar 1, 2013 at 15:39
  • is 'Enable Location' checked in your browser settings ? Commented Mar 1, 2013 at 16:31

1 Answer 1

1

I have used the below code on my android without issues. If you want to call the function again just set a timeout in the coordinates function.

if (navigator.geolocation) {
    console.log("true"); //gets logged
    navigator.geolocation.getCurrentPosition(coordinates);
} 

function coordinates(location) {
    latitude =  location.coords.latitude;
    longitude = location.coords.longitude;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.