ç¨æ·éè¿ç¹å»å°å¾ä¸é¢çä½ç½®ï¼å¨å°å¾ä¸é¢è¿è¡æç¹ï¼ç¶ååæè·åçå°çå°çä½ç½®ä¿åå°å°å¾ä¸é¢çå°åæ ç®ä¸ã
主è¦æ¯ç¾åº¦å°å¾APIç使ç¨
var map = new BMap.Map("allmap"); //å®ä¾åä¸ä¸ªå°å¾å¯¹è±¡
var point = new
BMap.Point(116.331398,39.897445); //设置å°å¾ä¸å¿çä½ç½®
map.centerAndZoom(point,12);
//设置å°å¾å
ç´ çå¯è§å±
map.enableScrollWheelZoom();
//å¯ç¨æ»è½®æ¾å¤§ç¼©å°ï¼é»è®¤ç¦ç¨
map.enableContinuousZoom();
//å¯ç¨å°å¾æ¯æ§ææ½ï¼é»è®¤ç¦ç¨
function myFun(result){
var cityName =
result.name;
map.setCenter(cityName);
}
var myCity = new
BMap.LocalCity();
myCity.get(myFun);
i=0
//ç¹å»è·ååæ
map.addEventListener("click",function(e){
if(i === 0)
{
//åå¨ç»çº¬åº¦
lng = e.point.lng;
lat =
e.point.lat;
//å¨å°å¾ä¸é¢æç¹
var marker = new BMap.Marker(new
BMap.Point(lng,lat)); // å建æ 注
map.addOverlay(marker);
marker.enableDragging(); //å¯ææ½
var gc = new
BMap.Geocoder();
//è·åå°åçæ°æ®å°å
var pt = e.point;
gc.getLocation(pt, function(rs){
var addComp =
rs.addressComponents;
address = addComp.province + addComp.city +
addComp.district + addComp.street + addComp.streetNumber;
//ç»å¾
var label = new BMap.Label(address,{offset:new
BMap.Size(20,-10)});
marker.setLabel(label);
});
i=1;
}
});