5

I have a Phonegap app. I am including cordova.js in the HTML (but not in the www directory), I am waiting for deviceready to be fired, and then I'm calling

navigator.geolocation.getCurrentPosition(successCallback,failCallback);

I'm receiving both versions of the dialog (in this order):

Native Dialog - https://i.stack.imgur.com/H5y1O.png
HTML Dialog - https://i.stack.imgur.com/XbcmR.png

MZimmerman6
  • 8,445
  • 10
  • 40
  • 70
bendalton
  • 778
  • 6
  • 8

4 Answers4

5

If you're using version 3+ of PhoneGap, make sure you're correctly including the plugin.

From the PhoneGap v3.0.0 API Docs :

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-line Interface, to add or remove this feature for a project

brandonjp
  • 3,018
  • 2
  • 28
  • 27
  • AH! this is perfect. I can't believe I missed this. – bendalton Sep 25 '13 at 18:57
  • @brandonjp If you have missed the installation of the plugin then how could the two messages appear for you? I have installed the plugin as it was discribed in the documentation and I still have both of the mentioned messages. Any Idea? – Dev DOS Mar 30 '15 at 08:25
  • Hello, How to Disable Location permission alert on iPhone with Cordova. – KAUSHAL J. SATHWARA Oct 26 '15 at 10:45
0

I had the same problem, that's because there was not successfully installed phonegap geolocation plugin. Do you know how install it? Please check how to on http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface

0

Do not call getCurrentPosition immediately after deviceready has been fired. geolocation plugin is not ready, so navigator.geolocation.getCurrentPosition actually calls HTML5 api, then you see the HTML dialog. I do below to make sure geolocation plugin is ready before calling navigator.geolocation.getCurrentPosition in my ionic project.

    var my_getposition = function() {
        if (ionic.Platform.isIOS() && !window.Coordinates) {
            $timeout(function(){ my_getposition(); }, 500);
            return;
        }
        navigator.geolocation.getCurrentPosition(...);
    }
poordeveloper
  • 2,272
  • 1
  • 23
  • 36
-1

You have to run "cordova prepare" in order to change the config.xml and it will automatically generate cordova_plugins.js that will be used for the geolocation plugin.

Just beware because when you do run cordova prepare it will erase all your /www folder.

Tipically you would have to add all the plugins and set up your environment before you add your code to the /www folder...