MapKit.MKDirections Class
An Apple-provided route to a destination.

See Also: MKDirections Members

Syntax

[Foundation.Register("MKDirections", true)]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.Mac_10_0 | ObjCRuntime.Platform.Mac_10_1 | ObjCRuntime.Platform.Mac_10_2 | ObjCRuntime.Platform.Mac_10_3 | ObjCRuntime.Platform.Mac_10_4 | ObjCRuntime.Platform.Mac_10_5 | ObjCRuntime.Platform.Mac_10_6 | ObjCRuntime.Platform.Mac_10_7 | ObjCRuntime.Platform.Mac_10_8 | ObjCRuntime.Platform.Mac_10_9 | ObjCRuntime.Platform.Mac_10_10 | ObjCRuntime.Platform.Mac_Version | ObjCRuntime.Platform.Mac_Arch64 | ObjCRuntime.Platform.Mac_Arch)]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_7_0)]
public class MKDirections : Foundation.NSObject

Remarks

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

Related content

Requirements

Namespace: MapKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0