Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript phonegap上的地理位置返回未定义_Javascript_Cordova_Geolocation - Fatal编程技术网

Javascript phonegap上的地理位置返回未定义

Javascript phonegap上的地理位置返回未定义,javascript,cordova,geolocation,Javascript,Cordova,Geolocation,我想从phonegap应用程序中的按钮调用地理定位函数。 这是我通过点击按钮调用的函数 function geolocalization () { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(searchstructures, showError, {timeout:60000}); } else { al

我想从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);
}

未捕获类型错误:无法读取坐标的未定义更改坐标的属性“纬度”