标签:ddc this 1.2 else res nts 需要 city 失败
1.引入 百度地图js(1.3以后需要key) <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
2.js如下:
var lat=32.4,lng=119.4,page=1;//默认扬州市经纬度
var areaName="扬州市";//定位获取城市 默认扬州市
getLocation();
function getLocation(){
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
lat = r.point.lat;
lng = r.point.lng;
var point = new BMap.Point(lng,lat);
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);
});
}else{
alert("定位失败")
}
});
}
标签:ddc this 1.2 else res nts 需要 city 失败
原文地址:http://www.cnblogs.com/dyf423/p/6228714.html