电话间隙上的地理位置返回未定义

Geolocation on phonegap returning undefined

本文关键字:地理位置 返回 未定义 电话间 间隙 电话      更新时间:2023-09-26

我想从我的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>

但我总是未定义为位置结果(成功函数中的警报总是打印未定义)。知道我做错了什么吗?

尝试使用

function searchstructures(position) {
        $('#formish').css('display', 'none');
        $('#loading').css('display', 'block');
        alert(position.coords.latitude + " " + position.coords.longitude);
}

查看文档