PhoneGap 版本:2.0.0。 Android API 级别 16(4.0.3 版本)。提示错误的代码示例:
navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true});
function onSuccess(position) {
console.log('latitude: '+ position.coords.latitude);
console.log('longitude: '+ position.coords.longitude);
}
function onError(error) {
console.log('Appeared error : '+ error.message);
}
模拟器总是报错Failed to start Geolocation service
, 错误代码2
。即使通过发送 GPS 坐标安卓控制台 or DDMS
Android 清单权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
你只在模拟器上测试这个吗?地理定位服务在我的 Android 模拟器中总是失败,但在真实设备上却不会。
编辑:请尝试使用以下代码
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(myPositionSuccess, myPositionError, {maximumAge: 300000, timeout:10000, enableHighAccuracy : true});
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)