function getLocation() {
if(navigator.geolocation) {
var getOption={
enableHighAccuracy:true,
timeout:8000,
maximumAge:0
};
navigator.geolocation.getCurrentPosition(showPosition, showError,getOption);
} else {
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(new BMap.Point(r.point.lng,r.point.lat));
//浏览器获取百度坐标
sessionStorage.setItem(‘x‘, r.point.lng)
sessionStorage.setItem(‘y‘, r.point.lat)
}else{
alert(‘failed‘+this.getStatus());
}
},{enableHighAccuracy: true})
}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("用户拒绝了地理定位的要求")
break;
case error.POSITION_UNAVAILABLE:
alert("无法获取地理位置信息")
break;
case error.TIMEOUT:
alert("无法获取地理位置信息");
break;
case error.UNKNOWN_ERROR:
alert("无法获取地理位置信息")
break;
}
}
//showPosition()
function showPosition(position) {
var y = position.coords.latitude;
var x = position.coords.longitude;
var ggPoint = new BMap.Point(x, y);
translateCallback = function (data){
if(data.status === 0) {
xy = [{
‘x‘: data.points[0].lng
}, {
‘y‘: data.points[0].lat
}]
sessionStorage.setItem(‘xy‘,JSON.stringify(xy))
sessionStorage.setItem(‘x‘,xy[0].x);
sessionStorage.setItem(‘y‘,xy[1].y);
gasno(1);
}
}
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(ggPoint);
convertor.translate(pointArr, 1, 5, translateCallback)
// BMap.Convertor.translate(ggPoint,2,translateCallback);
}