【发布时间】:2014-12-16 22:33:44
【问题描述】:
我想通过 phonegap 应用程序中的按钮调用地理定位功能。 这是我通过单击按钮调用的函数。
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>
但我总是得到未定义的位置结果(成功函数中的警报总是打印未定义)。 知道我做错了什么吗?
【问题讨论】:
标签: javascript cordova geolocation