简体   繁体   English

navigator.geolocation.getCurrentPosition Phonegap - 停止警报

[英]navigator.geolocation.getCurrentPosition Phonegap - Stop alerts

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. 当我调用navigator.geolocation.getCurrentPosition时,我得到两个警告框。 One native, and the other from the webview (Safari). 一个本机,另一个来自webview(Safari)。 The general answer is to place the call in the Deviceready call. 一般的答案是将呼叫置于Deviceready呼叫中。 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 谢谢

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. 如果您使用的是Cordova / PhoneGap 3.0或更高版本,请确保已将Geolocation插件添加到您的应用项目中,否则您将获得双重警报。

If using Cordova, cd into your project directory, then enter the following command in the command line: 如果使用Cordova,请cd进入项目目录,然后在命令行中输入以下命令:

cordova plugin add org.apache.cordova.geolocation

If using PhoneGap, you can try this command instead: 如果使用PhoneGap,您可以尝试使用此命令:

phonegap local plugin add org.apache.cordova.geolocation

Thanks to Robert Verge at https://stackoverflow.com/a/18839828 感谢Robert Verge, 网址https://stackoverflow.com/a/18839828

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM