Domanda

I'm using the new MKMapItem and all seems fine. When I use "openMapsWithItems" with that options I get the Maps App opened with the route from "plc" to "plc3" but I wanted to use all the 3 Placemarks like Start -> Point --> Destination. Is that possible?

NSMutableArray *arrayMapItem = [[NSMutableArray alloc] init];

MKPlacemark *plc = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(43.77398, 11.248) addressDictionary:nil];
MKMapItem *partenza = [[MKMapItem alloc] initWithPlacemark:plc];
[partenza setName:@"Piazza"];

MKPlacemark *plc2 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(43.780, 11.248) addressDictionary:nil];
MKMapItem *mezzo = [[MKMapItem alloc] initWithPlacemark:plc2];
[mezzo setName:@"Mezzo"];

MKPlacemark *plc3 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(43.783, 11.248) addressDictionary:nil];
MKMapItem *destinazione = [[MKMapItem alloc] initWithPlacemark:plc3];
[destinazione setName:@"Destinazione"];


[arrayMapItem addObject:partenza];
[arrayMapItem addObject:mezzo];
[arrayMapItem addObject:destinazione];

NSDictionary* options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         MKLaunchOptionsDirectionsModeDriving,
                         MKLaunchOptionsDirectionsModeKey, nil];

[MKMapItem openMapsWithItems:arrayMapItem launchOptions:options];
È stato utile?

Soluzione

From the MapKit documentation, it states:

If you specify the MKLaunchOptionsDirectionsModeKey option in the launchOptions dictionary, the mapItems array must have no more than two items in it. If the array contains one item, the Maps app generates directions from the user’s current location to the location specified by the map item. If the array contains two items, the Maps app generates directions from the location of the first item to the location of the second item in the array.

If you're using the MKLaunchOptionsDirectionsModeKey option, you should only pass two items in your array.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top