Search code examples
javascriptiosiphonegeolocationphonegap-build

Location permission alert shows up twice using Phonegap


I've been struggling with this for the past two days. I have looked at various responses but none have solved my problem. I am using Phonegap Build to publish an iPhone app. One on of the features is to get the user's current location. Before the map loads I get two alerts, the first one is a normal alert asking me if I want to grant my current location. However the second alert show a directory path where the file is located also asking if I want to grant the app permission to my location (see image below) I tried the following suggested solution here Location permission alert on iPhone with PhoneGap without any luck.

This is what I have in my config.xml file

<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>

I call the init function from the body tag

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

enter image description here I also tried these solutions but none work

How to prevent double prompt for geolocation in Phonegap app?

Location permission alert on iPhone with Cordova

What could I be doing wrong? Are there any examples or tutorials that anyone can recommend?


Solution

  • I finally figured it out, I added the following lines and the second alert no longer shows up

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