JS调用百度地图API进行地址解析的时候,解析不到详细地址
我使用JS调用百度地图API,经度:116.556186,纬度:23.616543进行地址解析,解析后的结果如下图,不够准确。代码如下:vargeo=newBMap.Ge...
我使用JS调用百度地图API,经度:116.556186,纬度:23.616543 进行地址解析,解析后的结果如下图,不够准确。
代码如下:
var geo = new BMap.Geocoder();
geo.getLocation(new BMap.Point(116.556186, 23.616543), function (result) {if (result) {var addComp = result.addressComponents;$(customCoordinate).find('.address').empty().append(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);}});
谁知道该怎么改才能显示详细地址? 展开
代码如下:
var geo = new BMap.Geocoder();
geo.getLocation(new BMap.Point(116.556186, 23.616543), function (result) {if (result) {var addComp = result.addressComponents;$(customCoordinate).find('.address').empty().append(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);}});
谁知道该怎么改才能显示详细地址? 展开
2个回答
展开全部
var map = new BMap.Map("container");
// 创建地图实例
var point = new BMap.Point(116.556186, 23.616543);
map.centerAndZoom(point, 18);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var pt = new BMap.Point(r.point.lng, r.point.lat)
var geoc = new BMap.Geocoder();
geoc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
console.log(JSON.stringify(addComp));
// alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
} else {
alert('failed' + this.getStatus());
}
}, { enableHighAccuracy: true })
// 创建地图实例
var point = new BMap.Point(116.556186, 23.616543);
map.centerAndZoom(point, 18);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var pt = new BMap.Point(r.point.lng, r.point.lat)
var geoc = new BMap.Geocoder();
geoc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
console.log(JSON.stringify(addComp));
// alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
} else {
alert('failed' + this.getStatus());
}
}, { enableHighAccuracy: true })
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var bm = new BMap.Map("allmap");//allmap为地图div的id
var point = new BMap.Point(116.556186, 23.616543);
bm.centerAndZoom(point, 18);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询