This code:
navigator.geolocation.getCurrentPosition(
function(position) {
alert(position.coords.latitude, position.coords.longitude);
},
function(error){
alert(error.message);
}, {
enableHighAccuracy: true
,timeout : 5000
}
);
https://jsfiddle.net/FcRpM/ works in Google Chrome at my laptop, but on mobile HTC one S (android 4.1, GPS off, location via mobile networks and wifi enabled), connected to internet via WiFi.
other android apps locates me correct.
You can try this. It seems to work on my device (Samsung Galaxy Nexus running Chrome 27.0.1453.90 on Wi-Fi (no data connection, no GPS on))
navigator.geolocation.getCurrentPosition( function(position) { alert("Lat: " + position.coords.latitude + "\nLon: " + position.coords.longitude); }, function(error){ alert(error.message); }, { enableHighAccuracy: true ,timeout : 5000 } );
The problem is that alert only takes strings (in it's original form) however you are passing 2 doubles. Modify the alert box for example to alert('Hey', 'Hello');
and the output will be only Hey
. Change the ,
to +
and you'll get the concatenated strings HeyHello
. You can't use a +
sign inside the alert
as the equation will be first executed and then displayed.
Hope this makes it clear.