ios-oc-Gold map draws routes based on two coordinate points __ios

Source: Internet
Author: User
Tags polyline



Since the start of the project to use the high-German map, but two items of the gold map of the map have been used, the basic process is the same.


1. Import the required SDK configuration ...

2.

Agent

<mamapviewdelegate, Amaplocationmanagerdelegate,amapsearchdelegate,amapnavidrivemanagerdelegate, Amapnavidriveviewdelegate>


Property

Map related

@property (Strong, nonatomic) Mamapview *mapview;

@property (Strong, nonatomic) Amaplocationmanager *locationmanager;

@property (Strong, nonatomic) mapointannotation *annotation; Map marking

@property (nonatomic, strong) Amaproute *route; Route planning

Navigation

@property (nonatomic, strong) Amapnavidrivemanager *drivemanager;

@property (nonatomic, strong) Amapnavipoint *startpoint;

@property (nonatomic, strong) Amapnavipoint *endpoint;


Set up agents

Self.drivemanager = [[Amapnavidrivemanager alloc] init];

[Self.drivemanager setdelegate:self];


Set starting point coordinates

Self.startpoint = [Amapnavipoint locationwithlatitude:startlat Longitude:startlon];

Self.endpoint = [Amapnavipoint locationwithlatitude:endlat Longitude:endlon];

Conduct route planning

[Self.drivemanager Calculatedriveroutewithstartpoints:@[self.startpoint]

Endpoints:@[self.endpoint]

Waypoints:nil

Drivingstrategy:amapnavidrivingstrategysingledefault];

#pragma mark-amapnavidrivemanager Delegate Route planning callback


-(void) Drivemanageroncalculateroutesuccess: (Amapnavidrivemanager *) Drivemanager

{

NSLog (@ "oncalculateroutesuccess");

Show path after successful calculation of road

[Self shownaviroutes];

}


Draw Route

-(void) shownaviroutes

{

if ([self.driveManager.naviRoutes Count] <= 0)

{

Return

}

[Self.mapview RemoveOverlays:self.mapView.overlays];

Show the path to the map

For (NSNumber *arouteid in [self.driveManager.naviRoutes AllKeys])

{

Amapnaviroute *aroute = [[Self.drivemanager naviroutes] Objectforkey:arouteid];

int count = (int) [[Aroute routecoordinates] count];

Add Path polyline

Cllocationcoordinate2d Coords[count];


for (int i = 0; i < count; i++)

{

Amapnavipoint *coordinate = [[Aroute routecoordinates] objectatindex:i];

Coords[i].latitude = [coordinate latitude];

Coords[i].longitude = [coordinate longitude];

}


Mapolyline *polyline = [Mapolyline polylinewithcoordinates:coords count:count];


[Self.mapview Addoverlay:polyline];

}

[Self.mapview showAnnotations:self.mapView.annotations Animated:no];

}


Set route color

-(Maoverlayrenderer *) Mapview: (Mamapview *) Mapview Rendererforoverlay: (ID <MAOverlay>) Overlay

{

if ([Overlay Iskindofclass:[mapolyline class]])

{

Mapolylinerenderer *polylinerenderer = [[Mapolylinerenderer alloc] initwithpolyline:overlay];

Polylinerenderer.strokecolor = [Uicolor Bluecolor];

Polylinerenderer.linewidth = 5.f;

return polylinerenderer;

}

return nil;


}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.