//GPS定位
navigator.geolocation.getCurrentPosition(onSuccess, onError,{enableHighAccuracy:true});
//GPS定位成功
function onSuccess(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
// 百度地图API功能
//GPS坐标
var xx = position.coords.longitude;
var yy = position.coords.latitude;
//alert(xx+','+yy);
var gpsPoint = new BMap.Point(xx,yy);
BMap.Convertor.translate(gpsPoint,0,translateCallback);
};
//GPS定位失败
function onError(error) {
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
switch(error.code)
{
case 1:
alert('您拒绝了使用位置共享服务,请手动输入您的就餐地址。!');
break;
default :
alert('获取位置失败,请手动输入您的就餐地址。!');
break;
}
}
转载于:https://my.oschina.net/jack088/blog/391734