Phonegap enable GPS/Location at app runtime

ぃ、小莉子 提交于 2019-12-30 06:05:49

问题


I am using jquery-ui-maps and HTML5 geolocation to show to the user a list of locations and I need to leverage the user's geolocation.

So, here is the use case,

  1. User does not have GPS/Location Services enabled.
  2. User opens the application and navigates to the view that calls navigator.geolocation to get the user's position
  3. The app errors out and notifies the user they must enable GPS/Location Services
  4. The user then navigates out of the app and enables GPS
  5. When the user comes back to the app and tries to view the map (calling the geolocation again) the app still isn't able to use GPS.

I believe I have narrowed it down to being a Phonegap issue where the GPS permissions are initialized at app load and never reevaluated.

My question is, can GPS be enabled during the runtime of the application or does Phonegap require an app reload to use the GPS?


回答1:


Phonegap does support realtime update of your GPS.

Here is a direct link:

http://docs.phonegap.com/en/3.1.0/cordova_geolocation_geolocation.md.html#geolocation.watchPosition

In general its called "watch position", and you can set the refresh timer yourself.

Regarding enabling the GPS during runtime.

Try just to call navigator.geolocation.watchPosition().

Remember to grant access to geolocation on your config.xml as well, but I guess you know that ;)

I hope it helped.




回答2:


after struggling for a while i found a plugin that was able to help me with the same issue

https://github.com/nishantsharmajecrc/cordova-dialog-gps

  function calldialog() {
 document.addEventListener("deviceready",function() {
 cordova.dialogGPS("Your GPS is Disabled, this app needs to be enable to          works.",//message
            "Use GPS, with wifi or 3G.",//description
            function(buttonIndex){//callback
              switch(buttonIndex) {
                case 0: break;//cancel
                case 1: break;//neutro option
                case 2: break;//user go to configuration
              }},
              "Please Turn on GPS",//title
              ["Cancel","Later","Go"]);//buttons
  });
  }


来源:https://stackoverflow.com/questions/19778828/phonegap-enable-gps-location-at-app-runtime

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