简体   繁体   English

geoLocation启用没有页面刷新?

[英]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. 目前,我们必须刷新网页(实际上是PhoneGap应用程序),如果GPS关闭并且(在通知用户之后)然后打开。

How can we update the GeoLocation status without the need to refresh the page/app ? 我们如何更新GeoLocation状态而无需刷新页面/应用程序?

为什么不简单地使用setInterval来检查每隔几秒钟的支持?

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. 尝试在多页phonegap + JQM应用中通过Google Maps API加载geoLocation时遇到了同样的问题。 A setInterval/setTimer did not work as well. setInterval / setTimer也不起作用。 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 onDeviceReady对我不起作用,因为未在index.html文件中调用地理位置

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() 然后使用附加到getLocation()的Javascript调用地理位置API

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM