Skip to content Skip to sidebar Skip to footer

Geolocation Enabling Without Page-refresh?

Currently, we have to refresh the web-page (actually PhoneGap app) if the GPS was off and (after notifying the user) then turned-on. How can we update the GeoLocation status withou

Solution 1:

Why not simply use a setInterval to check for support every few seconds?

Solution 2:

Hopefully this helps someone else out. I had the same issues with trying to load the geoLocation over Google Maps API in a multi page phonegap+JQM app. A setInterval/setTimer did not work as well. The only way i got it to work was doing a complete refresh also, kinda makes the app look broken.

onDeviceReady did not work for me either as geolocation was not called within index.html file

My solution was not to try to call geolocation when the geolocation view/page loads. Instead insert a button to call the script:

<ahref="#"onclick="getLocation();"data-role="button">Get My Location</a>

Then call the geolocation API with Javascript attached to getLocation()

function getLocation() {
        navigator.geolocation.getCurrentPosition(onSuccess ,onError,
      { timeout: 10000, enableHighAccuracy: true } );
        var lat;
        var lng;
    }

Post a Comment for "Geolocation Enabling Without Page-refresh?"