PhoneGap版本:2.0.0. Android API级别16(4.0.3版本).提示错误的代码示例: navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true});function onSuccess(position) { console.log('latitude: '+ positio
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); }
总是在模拟器中出错无法启动地理定位服务,错误代码2.即使通过Android控制台或DDMS发送GPS坐标
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}); };