【发布时间】:2013-08-04 19:42:08
【问题描述】:
我正在创建获取 Lat Lng 的 android 应用程序并检查我正在使用 PhoneGap GeoLocation Api 的用户的速度,但我只得到经度和纬度,但在高度和速度中它显示为空 这是我从 PhoneGap 网站获得的 JavaScript
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
var options = { enableHighAccuracy: true };
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('time');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
setTimeout('loop();',100);
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
function loop(){
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
</script>
我在 Android Mobile 和模拟器中检查了这个结果,两个地方都为空 Html部分是
<body>
<p id="time">Finding geolocation...</p>
【问题讨论】:
-
Geolocation API: "速度属性表示宿主设备当前速度的水平分量的大小,单位为米/秒。如果实现不能提供速度信息,则该属性的值必须为空。否则,速度属性的值必须为非负实数。 - 看起来您的设备/模拟器不支持获取速度信息
-
@Andreas -- 我如何检查我的设备是否支持获取速度信息?请有任何想法
-
如果
speed不是null...?! -
好的,那么我将成为其他设备,谢谢@Andreas
-
我测试了这个应用程序“Ulysse Speedometer By binarytoys”,它给出了移动物体的速度,所以我认为我的设备支持@Andreas
标签: javascript cordova geolocation