【问题标题】:Geolocation on phonegap returning undefinedphonegap 上的地理位置返回未定义
【发布时间】: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


    【解决方案1】:

    试试

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

    Check the doc

    【讨论】:

    • 未捕获的类型错误:无法读取未定义的属性“纬度”
    • 更改坐标的坐标
    猜你喜欢
    • 2021-05-10
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多