Reputation: 1101
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?
Upvotes: 0
Views: 357
Reputation: 11740
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;
}
Upvotes: 1