preface

Tencent map iOS SDK launched version 4.4.0, updated a number of more practical functions, this introduction to the map SDK administrative division retrieval function added a new administrative division outline point string, can let us draw the boundaries of administrative divisions on the map.

Usage scenarios

Draw the boundaries of administrative divisions

To prepare

Tencent Map iOS SDK

Drawing of a single administrative division

1, use QMSDistrictSearchSearchOption to initiate a single administrative districts retrieval functions

QMSDistrictSearchSearchOption *option = [[QMSDistrictSearchSearchOption   alloc] init];
Copy the code

2. Configure the retrieval parameter object, set the outline point string of administrative division, and initiate the retrieval:

option.keyword = @"110001"; / / need to pay attention to, this property will only take effect only when keyword for adcode option. Get_polygon = QMSDistrictPolygonWithSeaArea; [self.searcher searchWithDistrictSearchSearchOption:option];Copy the code

3. Obtain the retrieval results in the proxy method of MapView and draw them in the map:

- (void)searchWithDistrictSearchOption:(QMSDistrictBaseSearchOption *)districtSearchOption didRecevieResult:(QMSDistrictSearchResult *)districtSearchResult {

    NSArray *districtArray = districtSearchResult.result.firstObject;
    QMSDistrictData *data = districtArray.firstObject;

    CLLocationCoordinate2D coords[data.polygon.count];

    for (int i = 0; i < data.polygon.count; i++) {
        NSValue *coordValue = data.polygon[i];
        coords[i] = [coordValue coordinateValue];
    }

    QPolygon *polygon = [[QPolygon alloc] initWithWithCoordinates:coords count:data.polygon.count];
    [self.mapView addOverlay:polygon];
}


- (QOverlayView *)mapView:(QMapView *)mapView viewForOverlay:(id<QOverlay>)overlay {
    if ([overlay isKindOfClass:[QPolygon class]]) {
        QPolygonView *polygon = [[QPolygonView alloc] initWithPolygon:overlay];
        polygon.strokeColor = [UIColor redColor];
        polygon.lineWidth = 2;
    
        return polygon;
    }

    return nil;
}
Copy the code

4. Sample diagram

Drawing of several sub-administrative divisions

1, use QMSDistrictSearchSearchOption to initiate a single administrative districts retrieval functions

QMSDistrictChildrenSearchOption *option2 = [[QMSDistrictChildrenSearchOption alloc] init];
Copy the code

2. Configure the retrieval parameter object, set the outline point string of administrative division, and initiate the retrieval:

Option2.id = @"110000"; option2.id = @"110000"; [option2 setGet_polygon:QMSDistrictPolygonWithSeaArea]; [self.searcher searchWithDistrictChildrenSearchOption:option2];Copy the code

3. Sample diagram

conclusion

Administrative division retrieval can be used to display the user’s current region with the positioning function, and can also be used to display the administrative division function.

Akik: Batter

Link: www.jianshu.com/p/ae7351337…

Source: Jane Book

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