Phonegap 启用 gps 服务

Phonegap enable gps services

我正在编写一个使用 gps 的 phonegap 应用程序。我希望能够重定向到 gps 设置,以便我可以将其打开。我怎样才能做到这一点。之前的所有文章都展示了如何在 运行 时间启用 gps,代码已弃用。

经过一段时间的努力,我找到了一个能够帮助我解决问题的插件。

http://devpost.com/software/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
 });
 }    

特别是 Android,您可以使用 cordova-plugin-request-location-accuracy 从您的应用中切换 on/increase 定位服务的准确性(类似于 Google 地图的做法)。

这避免了需要切换到位置设置页面并让用户手动更改位置模式以启用 GPS。