kack kack - 5 months ago 13
jQuery Question

geolocation API is always track my location or not?

Now I am using

geolocation API
for get current location of user, but once I am allowed share my location then it will not asked again. But if my location will change then
geolocation API
give me old location or new location?

Answer

Finally, Got it my answer, if you want to track location then need to use watchPosition

Please find below code for track your location

<script>
var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.watchPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}
</script>
Comments