? map.addEventListener("click", function(e){?
? ? ? ? //通過(guò)點(diǎn)擊百度地圖磕道,可以獲取到對(duì)應(yīng)的point, 由point的lng、lat屬性就可以獲取對(duì)應(yīng)的經(jīng)度緯度? ?
? ? ? ? var pt = e.point;
? ? ? ? geoc.getLocation(pt, function(rs){
? ? ? ? ? ? //addressComponents對(duì)象可以獲取到詳細(xì)的地址信息
? ? ? ? ? ? var addComp = rs.addressComponents;
? ? ? ? ? ? //console.log(rs.point);
? ? ? ? ? ? mapchoice(rs.point);
? ? ? ? });? ? ? ?
? ? });
//點(diǎn)擊地圖定位顯示相關(guān)列表 function mapchoice(point){
?map.clearOverlays()
//刪除之前的標(biāo)注 var marker = new BMap.Marker(point);
?// 創(chuàng)建標(biāo)注map.addOverlay(marker);?
?// 將標(biāo)注添加到地圖中marker.setAnimation(BMAP_ANIMATION_BOUNCE);?
//跳動(dòng)的動(dòng)畫(huà) console.log(point);?
?if (0 === 0) { //alert('定位成功'); var url = "http://api.map.baidu.com/geocoder/v2/?ak=77AX39DjfpXutECiNSu1u2u63qQyAR3f&callback=renderReverse&location=" + point.lat + "," + point.lng + "&output=json&pois=1"; $.ajax({ type: "GET", dataType: "jsonp", url: url,?
?success: function(json)
?{ var loc = json.result.addressComponent; if (json.status == 0) { //console.log(json); var loc = json.result.addressComponent; $.ajax({ type:"post", url:"{:U('saveArea')}", data:{city:loc.city,area:loc.district},
?dataType:"text",?
?success:function(re){ if(re=='err'){ alert('定位失敗'); } } }) var htm = ""; var arr = json.result.pois; var cityname = json.result.addressComponent.province + json.result.addressComponent.city +json.result.addressComponent.district ; for(var i=0;i';
? ? ? ? ? ? }
? ? ? ? ? ? $('.address-list-ul').html(htm)? ? ? ? ?
? ? ? ? ? ? $('.address-list li').on('touchstart touchmove touchend',function(event){
? ? ? ? ? ? switch(event.type) {
? ? ? ? case 'touchstart':
? ? ? ? ? ? falg = false;
? ? ? ? ? ? break;
? ? ? ? case 'touchmove':
? ? ? ? ? ? falg = true;
? ? ? ? ? ? break;
? ? ? ? case 'touchend':
? ? ? ? ? ? if( !falg ) {
? ? ? ? ? ? $('.addressTextarea').val($(this).html())
$('.map-t').hide();
$('.province').html(cityname);
? ? ? ? ? ? console.log('點(diǎn)擊');
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? console.log('滑動(dòng)');
? ? ? ? ? ? }
? ? ? ? ? ? break;
? ? }
})
}
? ? ? ? },
? ? ? ? error: function(XMLHttpRequest, textStatus, errorThrown) {
? ? ? ? ? alert(latlon + "地址位置獲取失敗");
? ? ? ? }
? ? ? });
? ? }
? }
//進(jìn)入地圖 geolocation.getCurrentPosition(function(r){if(this.getStatus() == BMAP_STATUS_SUCCESS){
//地址轉(zhuǎn)換后觸發(fā)的函數(shù) translateCallback = function(data) {?
?var mk = new BMap.Marker(data.points[0]); map.addOverlay(mk); map.panTo(data.points[0]);
?//地圖左上角問(wèn)題 var nowHc2=document.documentElement.clientHeight/5;
//算出高的一半 var nowWc2=$(window).width()/2;
//寬的一半 map.panBy(nowWc2,nowHc2);
//定位 if (data.status === 0) {?
?//console.log(data) geoc.getLocation(data.points[0], function(rs){?
?//addressComponents對(duì)象可以獲取到詳細(xì)的地址信息?
?var addComp = rs.addressComponents;
?//console.log(rs)
?var mapcity = addComp.province + addComp.city + addComp.district ; $('.province').html(mapcity) }); var url = "http://api.map.baidu.com/geocoder/v2/?ak=77AX39DjfpXutECiNSu1u2u63qQyAR3f&callback=renderReverse&location=" + data.points[0].lat + "," + data.points[0].lng + "&output=json&pois=1";?
?$.ajax({ type: "GET", dataType: "jsonp", url: url, success: function(json) { var loc = json.result.addressComponent; if (json.status == 0) { console.log(json); var loc = json.result.addressComponent; $.ajax({ type:"post", url:"{:U('saveArea')}", data:{city:loc.city,area:loc.district}, dataType:"text", success:function(re){ if(re=='err'){ alert('定位失敗'); } } }); var htm = ""; var arr = json.result.pois; var cityname = json.result.addressComponent.province + json.result.addressComponent.city +json.result.addressComponent.district ; for(var i=0;i';
? ? ? ? ? ? }
? ? ? ? ? ? $('.address-list-ul').html(htm)? ? ? ? ?
? ? ? ? ? ? $('.address-list li').on('touchstart touchmove touchend',function(event){
? ? ? ? ? ? switch(event.type) {
? ? ? ? case 'touchstart':
? ? ? ? ? ? falg = false;
? ? ? ? ? ? break;
? ? ? ? case 'touchmove':
? ? ? ? ? ? falg = true;
? ? ? ? ? ? break;
? ? ? ? case 'touchend':
? ? ? ? ? ? if( !falg ) {
? ? ? ? ? ? $('.addressTextarea').val($(this).html())
$('.map-t').hide();
$('.province').html(cityname);
? ? ? ? ? ? console.log('點(diǎn)擊');
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? console.log('滑動(dòng)');
? ? ? ? ? ? }
? ? ? ? ? ? break;
? ? }
});
? ? ? ? ? }
? ? ? ? },
? ? ? ? error: function(XMLHttpRequest, textStatus, errorThrown) {
? ? ? ? ? alert(latlon + "地址位置獲取失敗");
? ? ? ? }
? ? ? });
? ? }
? } ;
? ? ? ? //地址轉(zhuǎn)換
? var pointArr = [];
? pointArr.push(r.point);
? var convertor = new BMap.Convertor();
? convertor.translate(pointArr, 1, 5, translateCallback);? ? ?
}
else {
alert('failed'+this.getStatus());
}? ? ? ?
},{enableHighAccuracy: true})