问题
I'm trying to set up a dictionary for my MKMapItem
, to open the native Map Application set to a certain location with a certain directions mode (walking, driving, transit, etc).
When I try to do the equivalent of this:
NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init];
[launchOptions setObject:MKLaunchOptionsDirectionsModeDriving forKey:MKLaunchOptionsDirectionsModeKey];
in C#, I can't find the key MKLaunchOptionsDirectionsModeKey
in Xamarin.
My DirectionsMode
value is here, and changed according to a parameter passed to my function.
MapKit.MKDirectionsMode LaunchOptionsDirectionsMode;
switch (sMode)
{
case 1:
LaunchOptionsDirectionsMode = MKDirectionsMode.Driving;
break;
case 2:
LaunchOptionsDirectionsMode = MKDirectionsMode.Driving;
break;
case 3:
LaunchOptionsDirectionsMode = MKDirectionsMode.Walking;
break;
default:
LaunchOptionsDirectionsMode = MKDirectionsMode.Driving;
break;
}
var emptyDict = new NSDictionary();
var endingCoord = new CoreLocation.CLLocationCoordinate2D(sLat, sLng);
var endLocation = new MKPlacemark(endingCoord, addressDictionary: emptyDict);
var endingItem = new MKMapItem(endLocation);
var launchOptions = new NSMutableDictionary();
var t = new MKMapItem();
launchOptions.Add(??????, LaunchOptionsDirectionsMode);
回答1:
You are looking for the MKDirectionsMode
Enum.
launchOptions.Add(MKDirectionsMode.Driving, LaunchOptionsDirectionsMode);
This is found in the MapKit
namespace.
UPDATE
You don't need to use a dictionary, in your case you can use the MKLaunchOptions
class to set the directions.
var launchOptions = new MKLaunchOptions();
launchOptions.DirectionsMode = LaunchOptionsDirectionsMode;
endingItem.OpenInMaps(launchOptions);
来源:https://stackoverflow.com/questions/44806903/xamarin-ios-mklaunchoptionsdirectionsmodekey