【问题标题】:Location permission alert shows up twice using Phonegap位置许可警报使用 Phonegap 显示两次
【发布时间】:2016-04-24 06:43:53
【问题描述】:

过去两天我一直在为此苦苦挣扎。我查看了各种回复,但都没有解决我的问题。我正在使用 Phonegap Build 发布一个 iPhone 应用程序。其中一项功能是获取用户的当前位置。在地图加载之前,我收到两个警报,第一个是正常警报,询问我是否要授予我当前的位置。但是,第二个警报显示文件所在的目录路径,还询问我是否要授予应用程序对我的位置的权限(见下图)我在这里尝试了以下建议的解决方案 Location permission alert on iPhone with PhoneGap 没有任何运气。

这是我的 config.xml 文件中的内容

<gap:plugin name="org.apache.cordova.geolocation" source="npm"/>

<allow-intent href="geo:*" />

<feature name="Geolocation">
    <param name="ios-package" value="CDVLocation" />
</feature>

<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>

<gap:config-file platform="ios" parent="NSLocationAlwaysUsageDescription" overwrite="false">
   <array>
      <string>needs your location</string>
   </array>
</gap:config-file>

我从body标签调用init函数

     function init(){
        document.addEventListener("deviceready",onDeviceReady,false);
     }
     function onDeviceReady(){
        navigator.geolocation.getCurrentPosition(success, fail);    
     }

我也尝试了这些解决方案,但没有奏效

How to prevent double prompt for geolocation in Phonegap app?

Location permission alert on iPhone with Cordova

我做错了什么?是否有任何人可以推荐的示例或教程?

【问题讨论】:

    标签: javascript ios iphone geolocation phonegap-build


    【解决方案1】:

    把你的地理定位代码放在platform.ready()中

    this.platform.ready().then(() => {
      this.geolocation.getCurrentPosition().then((resp) => {
          console.log(resp.coords.latitude);
          console.log(resp.coords.longitude);
    
    })
    

    【讨论】:

      【解决方案2】:

      我终于想通了,我添加了以下几行,第二个警报不再显示

      <script src="index.js"></script>
      <script src="cordova.js"></script>
      

      【讨论】:

      • 您添加了以下哪几行?
      猜你喜欢
      • 2010-12-13
      • 2015-06-24
      • 2017-05-08
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多