js 百度地图通过经纬度获取地名

首先引用百度 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);
});


你可能感兴趣的:(js 百度地图通过经纬度获取地名)