Javascript phonegap上的地理位置返回未定义
我想从phonegap应用程序中的按钮调用地理定位函数。 这是我通过点击按钮调用的函数Javascript phonegap上的地理位置返回未定义,javascript,cordova,geolocation,Javascript,Cordova,Geolocation,我想从phonegap应用程序中的按钮调用地理定位函数。 这是我通过点击按钮调用的函数 function geolocalization () { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(searchstructures, showError, {timeout:60000}); } else { al
function geolocalization () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(searchstructures, showError, {timeout:60000});
}
else {
alert("Geolocation is not supported by your device.");
}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
$('#loading').css('display', 'none');
$('#searchresult').css('display', 'none');
$('#formish').css('display', 'block');
}
function searchstructures(position) {
$('#formish').css('display', 'none');
$('#loading').css('display', 'block');
alert (position.coord);
...
AJAX CALL
...
}
config.xml文件还包含以下内容
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation"/>
</feature>
但是我总是得到未定义的位置结果成功函数中的警报总是打印未定义。
知道我做错了什么吗?试试看
function searchstructures(position) {
$('#formish').css('display', 'none');
$('#loading').css('display', 'block');
alert(position.coords.latitude + " " + position.coords.longitude);
}
未捕获类型错误:无法读取坐标的未定义更改坐标的属性“纬度”