位置权限警报使用 Phonegap 显示两次

Location permission alert shows up twice using Phonegap

过去两天我一直在为此苦苦挣扎。我查看了各种回复,但 none 解决了我的问题。我正在使用 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);    
     }

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

How to prevent double prompt for geolocation in Phonegap app?

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

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

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

将您的地理位置代码放入 platform.ready()

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

})