Enable geolocation without refreshing the page?

Currently we have to refresh the web page (actually the PhoneGap

app) if the GPS was turned off and (after notifying the user) then turns on.

How do I update the status GeoLocation

without refreshing the page / app?

+3


source to share


2 answers


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



+1


source


Hope this helps someone else. I had the same problems trying to load geoLocation via the Google Maps API in a multi-page phone + JQM app. SetInterval / setTimer didn't work either. The only way I got it was to do a full update and it looks like the app looks broken.

onDeviceReady did not work for me as geolocation was not being called in index.html file

My solution was to not try to trigger geolocation when uploading / downloading geolocation. Instead, insert a button to call the script:



<a href="#" 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;
    }

      

0


source







All Articles