Geocoder
构造函数
创建地址解析器实例
参数 类型 说明 opts可选object返回结果的语言
属性 类型 说明 language可选string返回结果的语言 返回值 Geocoder
示例代码1
const geocoder = new BMap.Geocoder();
geocoder.getPoint('北京市海淀区中关村', (point) => {
if (point) {
map.centerAndZoom(point, 16);
}
}, '北京市');
方法
- #getLocation(
point: Point,
callback: (result: GeocoderResult) => void,
options?: LocationOptions,
): void对指定坐标点进行反向地址解析,成功时以 GeocoderResult 为参数调用回调函数,失败时参数为 null
参数 类型 说明 pointPoint待解析的坐标点 callback(result: GeocoderResult) => void解析结果回调函数 options可选LocationOptions可选参数 属性 类型 说明 numPoisnumber返回的POI点个数,默认为10个。取值范围 poiRadiusnumber附近POI所处于的最大半径,默认为100米 返回值 void
示例代码1
geocoder.getLocation(new BMap.Point(116.404, 39.915), (result) => {
if (result) {
console.log('地址:', result.address);
}
});
对指定地址进行正向解析,定位成功时以 Point 为参数调用回调函数,失败时参数为 null
参数 类型 说明 addressstring地址字符串 callback(point: Point) => void解析结果回调函数 city可选string地址所在城市名,如 '北京市',默认为北京市返回值 void
示例代码1
geocoder.getPoint('北京市海淀区中关村', (point) => {
if (point) {
map.centerAndZoom(point, 16);
}
}, '北京市');
此类用于获取用户的地址解析。