最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - iOS Use Current Location Permission dialog is shown twice in Phonegap app - Stack Overflow

programmeradmin2浏览0评论

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

Share Improve this question edited Sep 25, 2013 at 16:27 MZimmerman6 8,63310 gold badges43 silver badges70 bronze badges asked Sep 25, 2013 at 16:00 bendaltonbendalton 7787 silver badges8 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 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 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...

发布评论

评论列表(0)

  1. 暂无评论