<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.3&key=2347e011114cc6bfa2b3265323ca65d7&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
<div id="container" style="display: none;"></div>
//獲取地址
var map = new AMap.Map('container',{
? ? ? ? ? ? ? ? resizeEnable: true,
? ? ? ? ? ? ? ? zoom: 13,
? ? ? ? ? ? });
map.plugin('AMap.Geolocation', function () {
? ? geolocation = new AMap.Geolocation({
? ? ? ? enableHighAccuracy: true,//是否使用高精度定位沽甥,默認(rèn):true
? ? ? ? timeout: 10000,? ? ? ? ? //超過10秒后停止定位搅荞,默認(rèn):無窮大
? ? ? ? maximumAge: 0,? ? ? ? ? //定位結(jié)果緩存0毫秒孤紧,默認(rèn):0
? ? ? ? convert: true,? ? ? ? ? //自動偏移坐標(biāo)躁愿,偏移后的坐標(biāo)為高德坐標(biāo)忧设,默認(rèn):true
? ? ? ? showButton: true,? ? ? ? //顯示定位按鈕脉课,默認(rèn):true
? ? ? ? buttonPosition: 'LB',? ? //定位按鈕妥劭矗靠位置夜惭,默認(rèn):'LB',左下角
? ? ? ? buttonOffset: new AMap.Pixel(10, 20),//定位按鈕與設(shè)置的托ル剩靠位置的偏移量赶站,默認(rèn):Pixel(10, 20)
? ? ? ? showMarker: true,? ? ? ? //定位成功后在定位到的位置顯示點(diǎn)標(biāo)記,默認(rèn):true
? ? ? ? showCircle: true,? ? ? ? //定位成功后用圓圈表示定位精度范圍纺念,默認(rèn):true
? ? ? ? panToLocation: true,? ? //定位成功后將定位到的位置作為地圖中心點(diǎn)贝椿,默認(rèn):true
? ? ? ? zoomToAccuracy:true? ? ? //定位成功后調(diào)整地圖視野范圍使定位位置及精度范圍視野內(nèi)可見,默認(rèn):false
? ? });
? ? map.addControl(geolocation);
? ? geolocation.getCurrentPosition();
? ? AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
? ? AMap.event.addListener(geolocation, 'error', onError);? ? ? //返回定位出錯信息
});
function onComplete(e){
if(I("text")==""){
var lng = e.position.lat;
var lat = e.position.lng;
$("#container").attr('data-lng',lng);
$("#container").attr('data-lat',lat);
$('#addr').text(e.formattedAddress)
}
}