3

This question has been asked many times, but each answer is the same, yet it doesn't work for me...

When I call navigator.geolocation.getCurrentPosition I get two alert boxes. One native, and the other from the webview (Safari). The general answer is to place the call in the Deviceready call. I am placing it in that listener, yet i still receive two alerts. (the second is very ugly!).

Any ideas on how to fix this??

document.addEventListener('deviceready', function() {
    navigator.geolocation.getCurrentPosition(initialize, onError, { enableHighAccuracy: true });
}

Any help would be great!

Thanks

Action_Turtle
  • 150
  • 11
  • What do the alerts say that you are getting? – Andrew Lively Sep 06 '13 at 18:52
  • Hi, thanks for the reply. I am getting an alert to allow the location for the app. which is normal for apps, but i then get an allow location for the index.html once the app fully loads. This is the one that needs removing... – Action_Turtle Sep 07 '13 at 18:15

1 Answers1

2

If you're using Cordova/PhoneGap 3.0 or greater, make sure you have added the Geolocation plugin to your app project, otherwise you'll get the double alert.

If using Cordova, cd into your project directory, then enter the following command in the command line:

cordova plugin add org.apache.cordova.geolocation

If using PhoneGap, you can try this command instead:

phonegap local plugin add org.apache.cordova.geolocation

Thanks to Robert Verge at https://stackoverflow.com/a/18839828

Community
  • 1
  • 1
wicketyjarjar
  • 1,755
  • 1
  • 13
  • 10
  • Hi, thanks for the time, but i get this error, after lots of "skipping existing file": { name: 'SyntaxError', message: 'Expected "/*", "=" or [A-Za-z0-9_] but "." found.', line: 458, column: 11 } – Action_Turtle Oct 07 '13 at 07:54
  • Just updated my original answer with revised plugin URLs that use a newer, more simpler format (though the old ones should still work too). – wicketyjarjar Oct 18 '13 at 15:16
  • But if you're still having troubles, I'd suggest upgrading to Cordova 3.1 (if you haven't already) and then try starting afresh with a brand new Cordova project. I think I remember having a similar problem once, and starting with a clean project fixed it. Just keep a copy of your existing project, create the new one, then copy back in your www folder, app icons, splashscreens and any settings you have previously changed in Xcode. Here's a Gist https://gist.github.com/wicketyjarjar/7042737 detailing the steps I commonly use to start a new Cordova project. – wicketyjarjar Oct 18 '13 at 15:16
  • Thanks for the update, i still get the same errors though... i will try a 3.1 update. see what happens. – Action_Turtle Oct 21 '13 at 08:51
  • Still no joy, i have now given up on PhoneGap, it seems to lead me into problems all over the app. I am now going to try and make this as a native iOS app... – Action_Turtle Nov 25 '13 at 09:35
  • Sorry to hear it's still not working for you. When everything is running correctly, Cordova is really good. Version 3.2.0 fixes a lot of issues and has just been released. It might be worth another try. Just run `sudo npm install -g cordova` from the command line to get the latest version. Otherwise, best of luck with the native development. I tried it unsuccessfully a few times before settling on Cordova. The ability to use the same code for iOS and Android is a big benefit. – wicketyjarjar Nov 25 '13 at 14:51