简体   繁体   English

科尔多瓦Android地理位置超时

[英]Cordova android geolocation timeout

I'm getting mad at trying to make geolocation working on Android I followed steps as explained in Cordova documentation pages My cordova version is 3.1.0-0.2.0 我为尝试使Android上的地理定位感到生气,我按照Cordova文档页面中所述的步骤进行操作。我的Cordova版本为3.1.0-0.2.0

$ cordova create myApp com.mymapackage.myApp myApp
$ cordova platform add ios
$ cordova platform add android
$ cordova plugin add org.apache.cordova.geolocation

AndroidManifest contains AndroidManifest包含

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

app/res/xml/config.xml contains app / res / xml / config.xml包含

<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>

I also copied the simple example to tryout geolocation 我还复制了一个简单的示例来试用地理位置

// Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        navigator.geolocation.getCurrentPosition(onSuccess, onError, { timeout: 30000, enableHighAccuracy: true });
    }

    // onSuccess Geolocation
    //
    function onSuccess(position) {
        var element = document.getElementById('geolocation');
        element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +
                'Longitude: '          + position.coords.longitude             + '<br />' +
                'Altitude: '           + position.coords.altitude              + '<br />' +
                'Accuracy: '           + position.coords.accuracy              + '<br />' +
                'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
                'Heading: '            + position.coords.heading               + '<br />' +
                'Speed: '              + position.coords.speed                 + '<br />' +
                'Timestamp: '          + position.timestamp                    + '<br />';
    }

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
                'message: ' + error.message + '\n');
    }

and all I can get is a timeout error. 我只能得到一个超时错误。 I have tried on many different target version/devices with ADT emulator, Genymotion emulator and cannot get anything out of geolocation position. 我已经使用ADT模拟器,Genymotion模拟器在许多不同的目标版本/设备上进行了尝试,但无法从地理位置位置获取任何信息。 By adding ios platform it was quite straight forward having location information when emulating using xCode. 通过添加ios平台,使用xCode进行仿真时很容易获得位置信息。

I'm starting getting desperate with this thing. 我开始对这件事感到绝望。 Any idea that could help? 任何有帮助的想法吗?

There is already issues reported upstream very similar to yours : "Geolocation watchPosition consistently timing out on Android 4.0.4 with Cordova 3.3.0" (issue.apache.org) 已经有报告的上游问题与您的非常相似:“ Geolocation watchPosition在使用Cordova 3.3.0的Android 4.0.4上持续超时”(issue.apache.org)

Moreover the cordova geolocation plugin is known to have multiple issues and will be deprecated soon[1]. 此外,众所周知,cordova地理位置插件存在多个问题,将很快弃用[1]。

The solution is to use regular browser-based geolocation. 解决方案是使用基于浏览器的常规地理位置。 The test given by MBillau[2] tries to use geolocation via the plugin and via the browser. MBillau [2]给出的测试尝试通过插件和浏览器使用地理位置。

The last option is to go native or to write your own plugin. 最后一个选择是本地化或编写自己的插件。

[1] https://issues.apache.org/jira/browse/CB-5977 [1] https://issues.apache.org/jira/browse/CB-5977

[2] https://github.com/apache/cordova-mobile-spec/blob/master/location/index.html [2] https://github.com/apache/cordova-mobile-spec/blob/master/location/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM