geoLocation enabling without page-refresh?

余生颓废 提交于 2019-12-10 22:07:43

问题


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 without the need to refresh the page/app ?


回答1:


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




回答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:

<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;
    }


来源:https://stackoverflow.com/questions/9862324/geolocation-enabling-without-page-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!