我正在尝试使用插件cordova-plugin-geolocation,但不起作用,我收到以下错误:
Uncaught ReferenceError: geolocationSuccess is not defined
我在清单中有正确的插件和权限,根本不起作用。如果有人知道解决方案,我感谢您的帮助。
Android最明显:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
的Javascript
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
');
};
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
答案 0 :(得分:1)
变化
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
到
navigator.geolocation.getCurrentPosition(onSuccess,
onError,
{
maximumAge: 3000,
timeout: 5000,
enableHighAccuracy: true
}
);