vue-baidu-map
vue-baidu-map copied to clipboard
希望引入"正/逆地址解析"功能
[功能请求] 希望引入"正/逆地址解析"功能
在线示例 URL
百度地图文档:https://lbsyun.baidu.com/index.php?title=jspopularGL/guide/geocoding
功能描述
地址解析服务提供从地址转换到经纬度的服务,反之,逆地址解析则提供从经纬度坐标转换到地址的转换功能
用法示例
// 百度地图的地址解析
var map = new BMapGL.Map('container');
map.centerAndZoom(new BMapGL.Point(116.331398,39.897445), 12);
//创建地址解析器实例
var myGeo = new BMapGL.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint('北京市海淀区上地10街', function(point){
if(point){
map.centerAndZoom(point, 16);
map.addOverlay(new BMapGL.Marker(point, {title: '北京市海淀区上地10街'}))
}else{
alert('您选择的地址没有解析到结果!');
}
}, '北京市')
// 百度地图的逆地址解析
var map = new BMapGL.Map("container");
map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
// 创建地理编码实例
var myGeo = new BMapGL.Geocoder();
// 根据坐标得到地址描述
myGeo.getLocation(new BMapGL.Point(116.364, 39.993), function(result){
if (result){
alert(result.address);
}
});
handler({ BMap }) {
this.BMap = BMap
},
onMapClick(type) {
const point = { ...type.point }
this.longitude = point.lng
this.latitude = point.lat
const geocoder = new this.BMap.Geocoder()
console.log(point)
console.log(new this.BMap.Point(point.lng, point.lat))
geocoder.getLocation(new this.BMap.Point(point.lng, point.lat), (geocoderResult) => {
if (geocoderResult) {
const address = geocoderResult.address
this.locationKeyword = address
}
})
}