如何获取当前位置在phonegap? [英] how to get current location in phonegap?
问题描述
我在我的应用程序中添加Geolocation插件,并使用此代码在phonegap中获取当前位置。但此代码无效。
document.addEventListener(deviceready,onDeviceReady,false);
function onDeviceReady(){
alert(4);
navigator.geolocation.getCurrentPosition(onSuccess,onError);
}
function onSuccess(position){
alert(1);
}
function onError(error){
alert(3);
}
我的代码中的问题在哪里?
>检查地理位置是否正确安装
重新启动手机(愚蠢的解决方案, >
检查您的地理位置权限在设备中打开设置
使用此代码测试
选项= {enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
使用eclipse logcat获取错误。
i add Geolocation plugin in my app and use this code for get current location in phonegap. but this code dose not work.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("4");
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position) {
alert("1");
}
function onError(error) {
alert("3");
}
Where is the problem in my code?
thank you and sorry for my poor english.
check if geolocation is properly installed or not
restart your phone (silly solution but it works sometimes.I faced it once)
check if your geo permissions & settings are turned on in device
test with this code
options = { enableHighAccuracy: true }; navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
If you're using android, try to get the error with eclipse logcat.
这篇关于如何获取当前位置在phonegap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!