PhoneGap Android 地理定位。某些属性始终为空
作为一个例子,我实现了一个方法,它向我展示了所有的地理位置信息。
function showLocation() {
navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError);
}
function onGeoSuccess(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: ' + new Date(position.timestamp) + '<br />';
}
所以我按下这个按钮绕着街区走了一圈:
<input type="submit" data-theme="d" name="login" id="login" value="Position" onclick="showLocation()"/>
但是,高度、航向和速度的属性始终显示为空。 海拔精度也显示为空,但phonegap文档说它不适用于android。那么为什么这不起作用呢? 预先感谢,丹尼尔
As an example I implemented a method wich shows me all the geolocation stuff.
function showLocation() {
navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError);
}
function onGeoSuccess(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: ' + new Date(position.timestamp) + '<br />';
}
so I took a walk arround the block pressing this button:
<input type="submit" data-theme="d" name="login" id="login" value="Position" onclick="showLocation()"/>
However, the Attributes for Altitude, Heading and Speed always shows null.
Altitude Accuracy also shows null, but the phonegap docu says it´s not working with android. So why is this not working?
thanks in advance, Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
dev.w3.org/geo/api/spec-source.html#coordinates_interface
它可能是特定于设备的,至于是否支持这些参数“如果实现无法提供{您遇到问题的那些变量}信息,该属性的值必须为空。”
dev.w3.org/geo/api/spec-source.html#coordinates_interface
it might be device specific, as to whether or not those parameters are supported "If the implementation cannot provide {those variables you're having trouble with} information, the value of this attribute must be null."
从我对phonegap 1.5 所做的测试中,我发现其中许多属性仅在我的设备处于运动状态时返回一个值。我确实得到了静止时的准确度数字(我想我的手机中有一个 GPS 传感器),它从几千米下降到不到 100 米。但是,我只能在设备移动时获得航向和速度。此外,航向是行进方向,它与手机的方向无关。
From the tests I have done with phonegap 1.5, I have found that many of these attributes only return a value if my device is in motion. I do get an accuracy number at rest (I think I have a gps sensor in my phone), it goes from a few thousand meters down to less than 100. However, I only get a heading and speed when the device is moving. Also the heading is the direction of travel, it is independent of the orientation of the phone.