高德地图初步使用-多点路线连接

demo下载
demo中存在错误:- (void)initRoute里面的 NSUInteger count = 14;就可以了。非常感谢读者的提醒。
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>iosamap</string>
</array>
1.这两个加到Info.plist 里

2.pod导入地图包

pod 'AMap3DMap' #3D地图SDK
pod 'AMapSearch' #搜索服务SDK
3.引头文件

#import <MAMapKit/MAMapKit.h>


4.签代理

<MAMapViewDelegate>


5.注册key

[MAMapServicessharedServices].apiKey =@"9efec5aeb9aa647cad07cd938a2587b8";


6.描绘路线

- (void)initRoute
{
    
    NSUInteger count = 11;
    CLLocationCoordinate2D * coords = malloc(count * sizeof(CLLocationCoordinate2D));
    
    coords[0] = CLLocationCoordinate2DMake(39.93563,  116.387358);
    coords[1] = CLLocationCoordinate2DMake(39.935564,   116.386414);
    coords[2] = CLLocationCoordinate2DMake(39.935646,  116.386038);
    coords[3] = CLLocationCoordinate2DMake(39.93586, 116.385791);
    coords[4] = CLLocationCoordinate2DMake(39.93586, 116.385791);
    coords[5] = CLLocationCoordinate2DMake(39.937983, 116.38474);
    coords[6] = CLLocationCoordinate2DMake(39.938616, 116.3846);
    coords[7] = CLLocationCoordinate2DMake(39.938888, 116.386971);
    coords[8] = CLLocationCoordinate2DMake(39.938855, 116.387047);
    coords[9] = CLLocationCoordinate2DMake(39.938172,  116.387132);
    coords[10] = CLLocationCoordinate2DMake(39.937604, 116.387218);
    coords[11] = CLLocationCoordinate2DMake(39.937489, 116.387132);
    coords[12] = CLLocationCoordinate2DMake(39.93614,  116.387283);
    coords[13] = CLLocationCoordinate2DMake(39.935622,  116.387347);
    
    [self showRouteForCoords:coords count:count];
    
    if (coords) {
        free(coords);
    }
    
}


7.显示标记点

- (void)showRouteForCoords:(CLLocationCoordinate2D *)coords count:(NSUInteger)count
{
    //show route
    MAPolyline *route = [MAPolyline polylineWithCoordinates:coords count:count];
    [self.map addOverlay:route];
    
    NSMutableArray * routeAnno = [NSMutableArray array];
    for (int i = 0 ; i < count; i++)
    {
        MAPointAnnotation * a = [[MAPointAnnotation alloc] init];
        a.coordinate = coords[i];
        a.title = @"route";
        [routeAnno addObject:a];
    }
    [self.map addAnnotations:routeAnno];
    [self.map showAnnotations:routeAnno animated:NO];
    
}


8.显示标记点间的直线

-(MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id<MAOverlay>)overlay
{
    if ([overlay isKindOfClass:[MAPolyline class]])
    {
        MAPolylineView *polylineView = [[MAPolylineView alloc] initWithPolyline:overlay];
        
        polylineView.lineWidth   = 3.f;
        polylineView.strokeColor = [UIColor colorWithRed:0 green:0.47 blue:1.0 alpha:0.9];
        
        return polylineView;
    }
    
    return nil;
}

9.创建地图

- (MAMapView *)map
{
    if (!_map)
    {
        _map = [[MAMapView alloc] initWithFrame:self.view.frame];
        [_map setDelegate:self];
        
        //加入annotation旋转动画后,暂未考虑地图旋转的情况。
        _map.rotateCameraEnabled = NO;
        _map.rotateEnabled = NO;
    }
    return _map;
}


最后:就可以看见画出的线路了

//显示地图

    [self.viewaddSubview:self.map];


//显示路径

    [selfinitRoute];


demo下载

demo中存在错误:- (void)initRoute里面的 NSUInteger count = 14;就可以了。非常感谢读者的提醒。













评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值