百度地图获取当前位置授权对于ipnone6s和ipone7没有用,别的机型都可以,下面贴代码:
(定义调用本地授权函数)
var getLocation = function(callback) {
var map = new BMap.Map("map");
//map.centerAndZoom(new BMap.Point(116.404,39.915), 15);
// 百度地图API功能
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var geocoder = new BMap.Geocoder();
geocoder.getLocation(new BMap.Point(r.longitude, r.latitude), function(e) {
callback({
province: e.addressComponents.province,
city: e.addressComponents.city,
district: e.addressComponents.district,
address: e.address,
longitude: r.longitude,
latitude: r.latitude
});
});
} else {
alert('位置获取失败,code:[' + this.getStatus() + ']');
}
}, {
enableHighAccuracy: true
});
};
(调用函数)
getLocation(function(r) {
form.x = r.latitude;
form.y = r.longitude;
if(r.address){
if(r.city.indexOf('市')!=-1){
form.city = r.city.replace('市', '');
}else{
form.city = '';
}
form.address = r.address;
document.getElementById('address').innerText = r.address;
moving(form.y,form.x);
}else{
document.getElementById('address').innerText = "正在跳转到地址输入页面";
setTimeout(function(){
location.href = '/map';
},2000);
}
});