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