I have some javascript code depending on geolocation.
var myLat = 0.0;
var myLng = 0.0;
function setCurrentPosition(position) {
myLat = position.coords.latitude;
myLng = position.coords.longitude;
}
function errorOccured() {
document.write("sorry, error occured :( ");
}
$(function() {
navigator.geolocation.getCurrentPosition(setCurrentPosition, errorOccured);
document.write(myLat + " " + myLng);
});
However, this code merely produces
0 0
instead of
"client's latitude here" "client's longitude here"
Why?
I am using Google Chrome, which surely supports geolocation. I also allowed my browser to track my location.