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 ?
为什么不简单地使用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. 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.