See Also: MKDirections Members
Application developers should be aware that sending too many routing requests from the same device may lead to a throttling error (see MapKit.MKErrorCode.LoadingThrottled).
To request routing, application developers must set the MKDirectionsApplicationSupportedModes key in the application's info.plist file. The following example shows an automobile routing request:
C# Example
var gg = new CLLocationCoordinate2D(37.8197, -122.4786);
var sfo = new CLLocationCoordinate2D(37.6189, -122.3750);
var ggAnnotation = new MKPointAnnotation() { Title = "Golden Gate Bridge", Coordinate = gg };
var sfoAnnotation = new MKPointAnnotation() { Title = "SFO", Coordinate = sfo };
mapView.ShowAnnotations(new MKPointAnnotation[] { ggAnnotation, sfoAnnotation }, false);
var emptyDict = new NSDictionary();
var req = new MKDirectionsRequest() {
Source = new MKMapItem(new MKPlacemark(gg, emptyDict)),
Destination = new MKMapItem(new MKPlacemark(sfo, emptyDict)),
TransportType = MKDirectionsTransportType.Automobile
};
var dir = new MKDirections(req);
dir.CalculateDirections((response, error) => {
if(error == null){
var route = response.Routes[0];
var rteLine = new MKPolylineRenderer(route.Polyline) {
LineWidth = 5.0f,
StrokeColor = UIColor.Purple
};
mapView.GetRendererForOverlay = (mv, ol) => rteLine;
mapView.AddOverlay(route.Polyline, MKOverlayLevel.AboveRoads);
}else{
Console.WriteLine(error);
}
});
