zoukankan      html  css  js  c++  java
  • 腾讯地图行政区划边界绘制教程来啦!!

    前言

    腾讯地图iOS SDK推出了4.4.0版本,更新了多个比较实用的功能,本次介绍地图SDK行政区划检索功能新添加的行政区划轮廓点串,可以让我们在地图上绘制行政区划的边界。

    使用场景

    绘制行政区划的边界

    准备

    腾讯地图iOS SDK

    单个行政区划绘制

    1、使用QMSDistrictSearchSearchOption类来发起单个行政区划检索功能

    QMSDistrictSearchSearchOption *option = [[QMSDistrictSearchSearchOption   alloc] init];
    

    2、配置检索参数对象,并设置行政区划轮廓点串,发起检索:

    option.keyword = @"110001";
    // 需要注意,该属性只有在keyword为adcode时才会生效
    option.get_polygon = QMSDistrictPolygonWithSeaArea;
    [self.searcher searchWithDistrictSearchSearchOption:option];
    

    3、在MapView的代理方法中获取检索结果,并绘制在地图中:

    - (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;
    }
    

    4、示例图

    image.png

    多个子行政区划绘制

    1、使用QMSDistrictSearchSearchOption类来发起单个行政区划检索功能

    QMSDistrictChildrenSearchOption *option2 = [[QMSDistrictChildrenSearchOption alloc] init];
    

    2、配置检索参数对象,并设置行政区划轮廓点串,发起检索:

    // 这里需要注意,子级行政区划检索需要根据父级的行政区划ID来检索
    option2.ID = @"110000";
    [option2 setGet_polygon:QMSDistrictPolygonWithSeaArea];
    [self.searcher searchWithDistrictChildrenSearchOption:option2];
    

    3、示例图

    image.png

    总结

    行政区划检索可以配合定位功能来展示用户当前所在的区域,也可以用于做行政区划的展示功能。

    作者:面糊

    链接:https://www.jianshu.com/p/ae7351337371

    来源:简书

    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 相关阅读:
    2017年5月19日13:58:17 问题记录
    2017年5月17日20:14:29 rabbitmq 消费 异常信息无法处理 导致轮询
    2017年5月12日15:10:46 rabbitmq不支持非阻塞调用服务器
    2017年5月11日17:43:06 rabbitmq 消费者队列
    2017年5月10日16:11:28 定义所有问题
    MyBatis Plus 只插入只有自增id字段的表
    Centos 7 关闭报警音
    关于git项目切换远程提交路径和提交仓库
    IDEA通过git回滚到某个提交节点或某个版本
    IDEA使用@Autowired注解报错解决方案
  • 原文地址:https://www.cnblogs.com/TencentLBS/p/14523119.html
Copyright © 2011-2022 走看看