您的位置:首页 > 其它

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

2016-01-06 11:02 363 查看
demo下载

<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

[MAMapServices
sharedServices].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.view
addSubview:self.map];

//显示路径

[self
initRoute];

demo下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: