首页 文章

在IONIC中使用cordova-plugin-geolocation打开地理定位

提问于
浏览
2

我正在使用IONIC V1我知道如何使用geolocation插件( cordova-plugin-geolocation ),它的工作原理 . 当我在我的 Map 部分时,我收到通知 "allow name_app to access to device location" .

enter image description here

如果我的答案是 ALLOW ,则应用程序假定 gps 已激活 .

但是在其他应用程序的风格中,我希望这能带我到我的设备的配置,以便我在图像中标记 gps 的激活,以便能够激活 gps ,以防它未被激活 . ( ubicación= ubication 在我的语言中)

enter image description here

我该怎么做?

1 回答

  • 1

    如果正确理解您的问题,如果未启用GPS,则需要打开本机 gps 设置 .

    您可以使用以下任何选项:

    Using cordova-diagnostic-plugin plugin

    isGpsLocationEnabled() diagnostic-plugin功能可以帮助您了解GPS是否启用 .

    以下是用法:

    cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled) {
            if (enabled) {
              //enabled 
            } else {
              // open location native location settings 
              cordova.plugins.diagnostic.switchToLocationSettings();
            }
          },
          function(error) {
            console.error("The following error occurred: " + error);
          });
    

    Using request-location-accuracy plugin

    如果位置精度插件的request()函数给你错误回调 . 在那里检查错误代码是否为ERROR_USER_DISAGREED,如果为true,则使用switchToLocationSettings() of cordova-diagnostic-plugin打开本机设置 .

    以下是用法:

    function onRequestSuccess(success) {
      console.log("Successfully requested accuracy: " + success.message);
    }
    function onRequestFailure(error) {
      console.error("Accuracy request failed: error code=" + error.code + "; error message=" + error.message);
      if (error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED) {
        if (window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")) {
          // open location native location settings using diagnostic plugin
          cordova.plugins.diagnostic.switchToLocationSettings();
        }
      }
    }
    cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
    

相关问题