Xamarin.iOS MKLaunchOptionsDirectionsModeKey

孤街浪徒 提交于 2021-02-17 03:15:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!