Seeing two geolocation prompts in a PhoneGap/Cordova application?

This post is more than 2 years old.

Are you using geolocation in your PhoneGap/Cordova application and seeing two prompts?

I was. Even more odd was the fact that one had the "nice" application name and one was the full path to the index.html. See the screen shots below.

In all my Googling for this issue, all I could find were warnings about using geolocation before the deviceready event had fired. I definitely had not made that mistake, so I was truly confused. Also - none of these reports mentioned multiple prompts. To make things even more confusing - if I reran my application I would only get the second, ugly, prompt. An application is supposed to remember that you gave it permission, so what the heck, right?

Turns out that I made the same mistake others have made with Cordova 3.0 - I forgot to add the geolocation plugin!

cordova plugin add org.apache.cordova.geolocation

Even without the plugin you are still able to use geolocation. I have no idea why it prompted twice (I'm sure some of the engineers could explain it), but as soon as I added the plugin the second prompt went away.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Martin posted on 11/4/2013 at 1:06 PM

This is why I'll stick with 2.9 for now. PG 3.x is based on a good idea but not in a productively usable state (yet). Most of the docs are outdated or spread across a dozen sites. 2.x was easy to use for people with less mobile background but with 3.x it's harder to even start.

Comment 2 by Aric Brown posted on 1/3/2014 at 2:45 AM

Hey Ray,

Do you know if the PhoneGap plugin for location is using the latest APIs for Android and iOS? I am specifically interested in the low power usage of Androids "Fused Location Provider" and the ability to detect "Activity Monitoring" such as walking, biking, driving, etc. I have not been able to find any documentation to indicate that the plugins where updated to include these.


Comment 3 by Raymond Camden posted on 1/3/2014 at 2:59 AM

As far as I know, no to all of what you said. I checked the plugin registry and didn't see anything related to it. You may want to ask on the Google Group to see if anyone worked on such a plugin and maybe never got around to publishing it. If you find anything at all, I'd love to hear it.

These are the Android docs for the activity monitoring stuff:

It definitely seems like this could be handled in PG.

Comment 4 by Ryan Murphy posted on 1/10/2014 at 2:21 AM

Thanks for the hint to the plugin not being installed.
My case was a bit different since I had run the 'plugin add' command.

But I also needed to run 'cordova prepare' or 'cordova build'.
Otherwise the plugin and cordova_plugins.js don't get copied from the platforms/{platform}/.staging/www folder.

I don't remember needing to run that on CLI version 3.2, but maybe I did it inadvertently.
I'm on 3.3.1 now.

Comment 5 by Raymond Camden posted on 1/10/2014 at 2:36 AM

Um, weird, how did you test w/o doing prepare or build in the first place? Afaik, if you do "cordova emulate" or run, it does a prepare/build for you.

Comment 6 by Ryan Murphy posted on 1/14/2014 at 4:34 AM

I always run through XCode, not with cordova emulate or run.
I have a symlink set up in the ios folder (and same for android) so that my shared web app is always in sync with my platform folder.
I know that's not how Cordova 3.0 CLI wants me to do things, and I run the risk of wiping out my www folder by running prepare, etc.. I've been resisting the change to move to CLI completely but I'll probably have to start to avoid the risk.

Comment 7 by Francesco Ferigo posted on 12/21/2014 at 3:45 PM

I did the same mistake ;-)