darksky
darksky

Reputation: 21049

iOS 6 Maps - Cannot Find Directions

I am trying to direct my users to iOS 6 native maps for directions from their current location to a latitude, longitude location as follows:

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:placeLocation addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
NSArray *mapItems = @[destination, currentLocation];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES};
[MKMapItem openMapsWithItems:mapItems launchOptions:options];

I have set my simulator to my latitude and longitude. What is wrong with my code here?

Upvotes: 0

Views: 661

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50129

the code is fine and works for me GIVEN there is a route possible

works when directions between currentLocation and destination can be given. if currentLocation is in the US, maps fails because it can't navigate from germany to the us. but if the currentLocation is in europe too, the maps app works fine :)

//placeMarkCoord fixed to germany
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.0, 10.0) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];

//currentLocation must be reachable from destination!
//MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.0, 11.0) addressDictionary:nil];
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:placemark];

NSArray *mapItems = @[destination, currentLocation];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES};
[MKMapItem openMapsWithItems:mapItems launchOptions:options];

Upvotes: 1

Related Questions