preface

AOI (Area of interest), also called area of interest, is similar to POI. POI is used to mark a point and AOI is used to mark an area. Click on a building in Tencent Map APP, the building will be surrounded by contour lines, and the related information of the building will be displayed, such as name, address, distance, telephone number and so on. As shown below:

Usage scenarios

Click the POI name in the map to display the aoI Ayer of the building, and obtain the relevant information of the building through the retrieval function of Tencent map SDK.

To prepare

1. Tencent MAP 3D SDK

2, AOILayer

3. Location retrieval

The core code

1. Listen to click the callback of POI to obtain POI information:

- (void)mapView:(QMapView *)mapView didTapPoi:(QPoiInfo *)poi { = nil && [_poiName isEqualToString:poi.name]) { _poiName = nil; [self removeAoiLayer]; return; } _poiName = poi.name; QMSPoiSearchOption *option = [[QMSPoiSearchOption alloc] init]; option.keyword = poi.name; / / retrieve the fixed in Beijing, if Beijing does not retrieved automatically extended regions [option setBoundaryByRegionWithCityName: @ "Beijing" autoExtend: YES center: poi. Coordinate]; / / initiate retrieval [self mapSearcher searchWithPoiSearchOption: option]; }Copy the code

2. Listen to the retrieve callback to get the ID of the POI. The search may return multiple POI data, and defaults to the first one closest to the currently clicked POI:

- (void)searchWithPoiSearchOption:(QMSPoiSearchOption *)poiSearchOption didReceiveResult:(QMSPoiSearchResult *) poiSearchResult {/ / resolve the POI id if (poiSearchResult. DataArray. Count > 0) {QMSPoiData * data = poiSearchResult.dataArray.firstObject; if (data.id_ ! = nil && data.id_.length > 0) { _poiData = data; _poiId = data.id_; // createAoiLayer [self createAoiLayer]; }}}Copy the code

Create AOILayer

_aoiLayer = [[QAOILayer alloc] initWithUID:_poiId]; [self.mapView addAOILayer:_aoiLayer callback:^(BOOL success) {if (success) {NSLog(@adddaoilayer);} else {NSLog(@adddaoilayer); }}];Copy the code

The above is the core code, in the Demo added for displaying information information panel and location function, interested students can download the complete example at the bottom of the article enter my code cloud.

Example: AOILayer to create Tencent’s Beijing headquarters building

review

There are still a few drawbacks to this feature, such as:

1. Some POI did not generate AOI information, and the coordinate points constituting the AOI plane were not disclosed possibly due to data confidentiality.

2. AOI ICONS and Outlines cannot be replaced temporarily. If the background is green as shown in the figure above, the outline is easily confused with the background.

3. The information retrieved by POI is relatively limited.

link

Interested students can download the Demo in the code cloud to try it out.

The above content is reprinted from the article “Click on building Effect imitating Tencent Map APP” by Miaomu.

Link: www.jianshu.com/p/8ab02aa1d…

Source: Jane Book

Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.