Cordova 3.1 和 Phone Gap Geolocation 在 Android 上因“位置检索超时”而失败

Posted

技术标签:

【中文标题】Cordova 3.1 和 Phone Gap Geolocation 在 Android 上因“位置检索超时”而失败【英文标题】:Cordova 3.1 and Phone Gap Geolocation fails with "Position retrieval timed out" on Android 【发布时间】:2013-10-24 13:45:39 【问题描述】:

复制步骤..

cordova create hello4 com.example.hello HelloWorld
cd hello4
cordova platform add android
cordova plugin add org.apache.cordova.geolocation

将 index.html 替换为 完整示例,来自此处:http://docs.phonegap.com/en/3.1.0/cordova_geolocation_geolocation.md.html#Geolocation

将此添加到 config.xml

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

那么……

cordova build android
cordova run android

这会产生错误:代码 3 位置检索超时。

我也尝试过使用 Phone Gap 在线生成器,但无济于事。有谁知道如何解决这个问题?

非常感谢

【问题讨论】:

【参考方案1】:

我在 Phonegap v3.1.0 上看到了同样的问题,但在 v2.9.0 上没有 - 请参阅我的 answer to this question:

是的,您是对的,在 Phonegap v3.x - 我安装了 3.1.0-0.15.0。我看到的是一样的: 单次正确位置,则出现超时错误,触发 清除/重新添加观察者,然后是正确的位置。跑步 Phonegap 2.9.0 上的相同测试应用程序,它工作正常,成功 检索职位。这次我使用了选项 maximumAge: 0, timeout: 30000, enableHighAccuracy: true ;

看看你是否得到相同的结果:here's the v3.1.0 project&APK 和 here's the v2.9.0 project&APK。

这是我使用 Phonegap 3.1.0 构建时的 logcat:

10-24 20:50:29.287: I/Web Console(17092): Device Ready at :1171167449
10-24 20:50:59.287: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167509
10-24 20:51:29.328: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167509
10-24 20:51:59.337: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167445
10-24 20:52:28.397: I/Web Console(17092): Position updated: latitude=50.64626501666667, longitude=-4.736916616666666, accuracy=17m
at :-1468095491
10-24 20:52:28.397: I/Web Console(17092): Position updated: latitude=50.64626501666667, longitude=-4.736916616666666, accuracy=17m
at :-1468095491
10-24 20:52:58.407: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167445
10-24 20:53:27.878: I/Web Console(17092): Position updated: latitude=50.646433849999994, longitude=-4.736890766666666, accuracy=8m
at :-1468095491
10-24 20:53:27.878: I/Web Console(17092): Position updated: latitude=50.646433849999994, longitude=-4.736890766666666, accuracy=8m
at :-1468095491
10-24 20:53:57.887: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167445
10-24 20:54:27.367: I/Web Console(17092): Position updated: latitude=50.64643435, longitude=-4.736896850000001, accuracy=9m at
:-1468095491
10-24 20:54:27.367: I/Web Console(17092): Position updated: latitude=50.64643435, longitude=-4.736896850000001, accuracy=9m at
:-1468095491
10-24 20:54:57.377: I/Web Console(17092): Error while retrieving current position. Error code: 3,Message: Position retrieval timed out.
at :1171167445

当我使用它构建它时,这是来自完全相同的应用程序的 logcat Phonegap v2.9.0:

10-24 21:10:19.698: I/Web Console(19755): Device Ready at :1172318425
10-24 21:10:22.487: I/Web Console(19755): Position update rejected because accuracy of45m is less than required 20m at :1172318349
10-24 21:10:54.697: I/Web Console(19755): Position updated: latitude=50.646209633333335, longitude=-4.737049566666667, accuracy=9m
at :1172318421
10-24 21:10:55.177: I/Web Console(19755): Position updated: latitude=50.64623646666667, longitude=-4.7369963, accuracy=9m at
:1172318421
10-24 21:10:56.177: I/Web Console(19755): Position updated: latitude=50.64623674999999, longitude=-4.736949983333333, accuracy=9m
at :1172318357
10-24 21:10:57.677: I/Web Console(19755): Position updated: latitude=50.646237033333335, longitude=-4.73695015, accuracy=9m at
:1172318357
10-24 21:10:58.677: I/Web Console(19755): Position updated: latitude=50.646238333333336, longitude=-4.736944716666667, accuracy=9m
at :1172318357
10-24 21:10:59.747: I/Web Console(19755): Position updated: latitude=50.6462348, longitude=-4.736952216666666, accuracy=9m at
:1172318357
10-24 21:11:00.667: I/Web Console(19755): Position updated: latitude=50.64623206666667, longitude=-4.73695695, accuracy=9m at
:1172318357
10-24 21:11:01.677: I/Web Console(19755): Position updated: latitude=50.646232700000006, longitude=-4.7369544999999995,
accuracy=9m at :1172318357
10-24 21:11:02.677: I/Web Console(19755): Position updated: latitude=50.646232700000006, longitude=-4.7369544999999995,
accuracy=12m at :1172318357
10-24 21:11:03.687: I/Web Console(19755): Position updated: latitude=50.64623241666666, longitude=-4.736952116666667, accuracy=12m
at :1172318357
10-24 21:11:04.207: I/Web Console(19755): Position updated: latitude=50.646240533333334, longitude=-4.736951266666667,
accuracy=12m at :1172318357
10-24 21:11:05.187: I/Web Console(19755): Position updated: latitude=50.646235399999995, longitude=-4.736953183333334,
accuracy=12m at :1172318357
10-24 21:11:06.197: I/Web Console(19755): Position updated: latitude=50.6462522, longitude=-4.736926933333334, accuracy=12m at
:1172318357
10-24 21:11:07.197: I/Web Console(19755): Position updated: latitude=50.646253949999995, longitude=-4.736931416666667,
accuracy=12m at :1172318357
10-24 21:11:07.517: I/Web Console(19755): Position update rejected because accuracy of45m is less than required 20m at :1172318357
10-24 21:11:08.197: I/Web Console(19755): Position updated: latitude=50.64624196666667, longitude=-4.736951366666666, accuracy=9m
at :1172318357
10-24 21:11:09.697: I/Web Console(19755): Position updated: latitude=50.646261833333334, longitude=-4.73694825, accuracy=9m at
:1172318357
10-24 21:11:10.697: I/Web Console(19755): Position updated: latitude=50.64627816666666, longitude=-4.736968816666666, accuracy=9m
at :1172318357
10-24 21:11:11.197: I/Web Console(19755): Position updated: latitude=50.64627698333334, longitude=-4.736982066666667, accuracy=9m
at :1172318357
10-24 21:11:12.197: I/Web Console(19755): Position updated: latitude=50.646291033333334, longitude=-4.736992866666667, accuracy=9m
at :1172318357
10-24 21:11:13.197: I/Web Console(19755): Position updated: latitude=50.646285549999995, longitude=-4.73696835, accuracy=9m at
:1172318357
10-24 21:11:14.197: I/Web Console(19755): Position updated: latitude=50.64628801666666, longitude=-4.736988766666667, accuracy=9m
at :1172318357
10-24 21:11:15.197: I/Web Console(19755): Position updated: latitude=50.646256433333335, longitude=-4.736974683333333, accuracy=9m
at :1172318357
10-24 21:11:16.197: I/Web Console(19755): Position updated: latitude=50.64623895, longitude=-4.736980716666666, accuracy=9m at
:1172318357
10-24 21:11:17.207: I/Web Console(19755): Position updated: latitude=50.646249616666665, longitude=-4.736948533333333, accuracy=9m
at :1172318357
10-24 21:11:18.207: I/Web Console(19755): Position updated: latitude=50.64624111666667, longitude=-4.7369412833333335, accuracy=9m
at :1172318357
10-24 21:11:19.217: I/Web Console(19755): Position updated: latitude=50.64624506666667, longitude=-4.7369719, accuracy=9m at
:1172318357
10-24 21:11:20.207: I/Web Console(19755): Position updated: latitude=50.646218950000005, longitude=-4.7369769999999995,
accuracy=9m at :1172318357
10-24 21:11:21.207: I/Web Console(19755): Position updated: latitude=50.64621395000001, longitude=-4.7369834, accuracy=9m at
:1172318357
10-24 21:11:22.207: I/Web Console(19755): Position updated: latitude=50.646217416666666, longitude=-4.736986783333333,
accuracy=12m at :1172318357
10-24 21:11:23.207: I/Web Console(19755): Position updated: latitude=50.646211816666664, longitude=-4.7369768500000005,
accuracy=12m at :1172318357
10-24 21:11:24.707: I/Web Console(19755): Position updated: latitude=50.646210450000005, longitude=-4.736994233333333,
accuracy=12m at :1172318357
10-24 21:11:25.707: I/Web Console(19755): Position updated: latitude=50.64621571666667, longitude=-4.736988583333333, accuracy=12m
at :1172318357
10-24 21:11:26.707: I/Web Console(19755): Position updated: latitude=50.646216466666665, longitude=-4.7370037, accuracy=12m at
:1172318357
10-24 21:11:27.707: I/Web Console(19755): Position updated: latitude=50.64621723333333, longitude=-4.737019266666667, accuracy=20m
at :1172318357
10-24 21:11:28.717: I/Web Console(19755): Position updated: latitude=50.64621738333334, longitude=-4.737011333333333, accuracy=12m
at :1172318357
10-24 21:11:29.717: I/Web Console(19755): Position updated: latitude=50.64621768333333, longitude=-4.7370187, accuracy=18m at
:1172318357
10-24 21:11:30.727: I/Web Console(19755): Position updated: latitude=50.64621798333333, longitude=-4.737026116666667, accuracy=18m
at :1172318357

【讨论】:

为回复干杯。我最终编写了自己的地理位置科尔多瓦插件,但降级可能是一个更清洁的解决方案。【参考方案2】:

我可以确认这个问题。我从未使用示例中的以下代码获得 GPS 修复(错误代码 3,位置检索超时):

<!DOCTYPE html>
<html>
<head>
    <title>Device Properties Example</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

    // 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');
    

</script>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>

但是,在 genymotion 模拟器中,您可以在任意位置模拟 GPS 设备,它工作得很好!

这里有人有解决方案吗?我正在使用装有 Android 4.1.1 的 HTC One X 设备。 GPS 已启用并可在其他应用上运行。

【讨论】:

你找到解决办法了吗?

以上是关于Cordova 3.1 和 Phone Gap Geolocation 在 Android 上因“位置检索超时”而失败的主要内容,如果未能解决你的问题,请参考以下文章

Phone Gap 中的输入字段表单问题

Phone Gap Windows Build 访问规则

sencha + Phone Gap中的相机应用程序[关闭]

Phonegap/Cordova 2.7.0:未找到 exec_gap 文件

图像未显示在 Phone Gap 应用程序中

(ios + phone gap) - 使用仪器配置最终应用程序