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 - .png
HTML Dialog - .png
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.sstatic/H5y1O.png
HTML Dialog - https://i.sstatic/XbcmR.png
4 Answers
Reset to default 5If 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 mand, described in The Command-line Interface, to add or remove this feature for a project
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./en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface
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(...);
}
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...