当打开地图的时候,百度地图自动检测到自己的当前位置并且显示出来!
在phoneg中我用一下方法,为什么在android系统2.3下没有效果???
Device Properties Example// 等待加载PhoneGap
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap加载完毕
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// 获取位置信息成功时调用的回调函数
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '
' +
'Longitude: ' + position.coords.longitude + '
' +
'Altitude: ' + position.coords.altitude + '
' +
'Accuracy: ' + position.coords.accuracy + '
' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '
' +
'Heading: ' + position.coords.heading + '
' +
'Speed: ' + position.coords.speed + '
' +
'Timestamp: ' + new Date(position.timestamp) + '
';
}
// onError回调函数接收一个PositionError对象
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
Finding geolocation...