逆地理编码
逆地理编码又称地址解析,指的是从已知的地理坐标到对应的地址描述(如省市、街区、楼层、房间等)的转换服务。
【Navinfo Navigation SDK for iOS】仅支持中国范围内的逆地理编码及逆地理编码服务,不支持英文或汉语拼音中国地图数据。
逆地理编码分为在线逆地理和离线逆地理两种模式(默认在线),通过MBReverseGeocoder发送reverseGeocodeFromPoint消息并设置代理回调来获得逆地理信息。
(完整代码详见 SDKDemo工程的 MBReverseGeocodeController.m)
// 以地图中心点为例进行逆地理
// 初始化MBReverseGeocoder
reverseGeocoder = [[MBReverseGeocoder alloc]init];
// 设置代理
reverseGeocoder.delegate = self;
// 获取地图中心点
MBPoint worldCenter = mapView.worldCenter;
// 发起逆地理请求
[reverseGeocoder reverseGeocodeFromPoint:&worldCenter];
// 逆地理成功回调
- (void)reverseGeocoder:(nonnull MBReverseGeocoder *)reverseGeocoder reverseGeocodeSucceededWithResult:(nonnull MBReverseGeocoderResult *)rgResult {
if (rgResult){
reverseGeocodeObject = rgResult;
CGPoint pivot = {0.5,0.5};
// 添加气泡(具体请参考 地图覆盖物-气泡展示)
annotation = [[MBAnnotation alloc]initWithZLevel:1 pos: rgResult.postion iconId:1004 pivot:pivot];
annotation.title = rgResult.poiName;
[baseMapView addAnnotation:annotation];
MBCalloutStyle calloutStyle = annotation.calloutStyle;
calloutStyle.anchor.x = 0.5f;
calloutStyle.anchor.y = 0;
annotation.calloutStyle = calloutStyle;
[annotation showCallout:YES];
}
}
运行后,点击逆地理编码显示结果:
