I want to get my position each timeinterval using navigator.geolocation.watchPosition
Later on I want to store these coordinates in a xml file.
The problem is the watchPosition
function does not call the getLocation
function.
function trackCoords ()
{
if (navigator.geolocation)
{
var options = { frequency: 3000 };
watchID = navigator.geolocation.watchPosition(getLocation, locationFail, options);
}
}
function getLocation(position) {
alert();
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert('latitude: ' + latitude + ' longitude: ' + longitude);
}
function locationFail() {
document.write('We did not get your location');
}
Thanks in advance
I think you're not calling trackCoords. Does the browser ask you for permission to be geolocalized? If I add trackCoords()
at the end of your script it seems to work for me:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.