0

My app allows to display Apple Map, pin location and find shortest route, draw line from two points. I known way to draw line on map, but I don't know how to find array of points between two points to draw. Have any suggestion for me? I don't use google map API. Thanks.

LViet
  • 113
  • 11

1 Answers1

0

If using iOS7 you can get the route like this:

// start and end point coordinates
CLLocationCoordinate2D *startPoint = CLLocationCoordinate2DMake(53.3478, -6.2597);
CLLocationCoordinate2D *endPoint = CLLocationCoordinate2DMake(53.2178, -6.6637);

// create a placemark and map item for your start point
MKPlacemark *startPlacemark = [[MKPlacemark alloc]initWithCoordinate:startPoint addressDictionary:nil];
MKMapItem *startMapItem = [[MKMapItem alloc]initWithPlacemark:startPlacemark];

// create a placemark and map item for your end point
MKPlacemark *endPlacemark = [[MKPlacemark alloc]initWithCoordinate:endPoint addressDictionary:nil];
MKMapItem *endMapItem = [[MKMapItem alloc]initWithPlacemark:endPlacemark];

// create your directions request
MKDirectionRequest *request = [[MKDirectionRequest alloc]init];
request.source = startMapItem;
request.destination = endMapItem;
request.requestAlternateRoute = NO; // or you can set this to YES if you wish

// get your directions
MKDirections *directions = [[MKDirections alloc]initWithRequest:request];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error){

 if(response.routes.count)
 {
  MKRoute *route = [response firstObject];
  [mapView addPolyline:route.polyline level:MKOverlayLevelAboveRoads];
 }

}];
Pancho
  • 4,099
  • 1
  • 21
  • 32