1、编写坐标点地址解析方法
/** * 坐标点地址解析 * @param point 经纬度点对象 */ getGeocoderInfoByPoint:functionpoint){ Geocoder.getLocationpoint, functionrs) { var addComp = rs.addressComponents; Geocoder.point=point; Geocoder.city=addComp.city; Geocoder.address=addComp.province + " " + addComp.city + " " + addComp.district + " " + addComp.street+ " " + addComp.streetNumber; }); return Geocoder; }
2、注册地图事件
moveend:functiontagId){ map.addEventListener"moveend",functione){ var point=map.getCenter); BmapUtils.getGeocoderInfoByPointpoint); $"#"+tagId).htmlGeocoder.city); }); }, dragend:functiontagId){ map.addEventListener"dragend",function){ var point=map.getCenter); BmapUtils.getGeocoderInfoByPointpoint); $"#"+tagId).htmlGeocoder.city); }); }, tilesloaded:functiontagId){ map.addEventListener"tilesloaded",function){ var point=map.getCenter); BmapUtils.getGeocoderInfoByPointpoint); $"#"+tagId).htmlGeocoder.city); }); }
3、调用注册事件处理
//动态改变地图显示城市 BmapUtils.event.moveend"curCity"); BmapUtils.event.dragend"curCity"); BmapUtils.event.tilesloaded"curCity");
注:解析坐标的方法在BmapUtils下,而事件方法在BmapUtils.event下;可以在之前发布版本上添加。
