//百度
layer.msg('正在定位,請稍後');
var geolocation = new BMap.Geolocation({
enableHighAccuracy: true, //是否使用高精度定位,默認:true
timeout: 10000, //超過10秒後中止定位,默認:無窮大
maximumAge: 0, //定位結果緩存0毫秒,默認:0
convert: true, //自動偏移座標,偏移後的座標爲高德座標,默認:true
showButton: true, //顯示定位按鈕,默認:true
buttonPosition: 'LB', //定位按鈕停靠位置,默認:'LB',左下角
buttonOffset: new BMap.Pixel(10, 20), //定位按鈕與設置的停靠位置的偏移量,默認:Pixel(10, 20)
showMarker: true, //定位成功後在定位到的位置顯示點標記,默認:true
showCircle: true, //定位成功後用圓圈表示定位精度範圍,默認:true
panToLocation: true, //定位成功後將定位到的位置做爲地圖中心點,默認:true
zoomToAccuracy: true //定位成功後調整地圖視野範圍使定位位置及精度範圍視野內可見,默認:false
});
geolocation.getCurrentPosition(function(r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
mk = new BMap.Marker(r.point);
getAddress(r.point);
} else {
alert('failed' + this.getStatus());
}
});
function getAddress(point) {
$('#lat').text(point.lat);
$('#lng').text(point.lng);
console.log('百度point', point.lat);
bd_decrypt(point.lat,point.lng);
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs) {
var addComp = rs.addressComponents;
var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber; //獲取地址
});
};
//很是不許,建議仍是用高德。緩存