如何在phonegap中获取当前位置? [英] how to get current location in phonegap?

查看:13
本文介绍了如何在phonegap中获取当前位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中添加了地理定位插件,并使用此代码获取 phonegap 中的当前位置.但是这段代码不起作用.

i added Geolocation plugin in my app and used this code for getting the current location in phonegap. but this code does 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.

推荐答案

  1. 检查地理定位是否正确安装

  1. 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

用这段代码测试

options = { enableHighAccuracy: true };navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

如果您使用的是 android,请尝试使用 eclipse logcat 获取错误.

If you're using android, try to get the error with eclipse logcat.

这篇关于如何在phonegap中获取当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆