百度地图api

1.百度地图精确定位

// 地址解析器 根据经纬度获取当前车辆所在地址
var gc = new BMap.Geocoder(); 
gc.getLocation(pointAdd, function(rs)
{
 var addComp = rs.addressComponents;
 var adr="车辆: "+chepai+"\r\r"+"位于: "+addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
 //创建信息窗口,点击标注时显示标注对应的车牌号码以及当前地址
 var infoWindow1 = new BMap.InfoWindow(adr);
 marker.addEventListener("click", function(){this.openInfoWindow(infoWindow1);});
});
首先引用百度 script

<script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&ak=百度密钥&v=1.0"></script>



然后 javascript :

// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs){
   var addComp = rs.addressComponents;
   alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});

相关推荐