1

I'm working on a Core Data project and early on I discovered MKMapItems are not NSCoder compliant, so I'm storing MKMapItems' coordinates as doubles in core data and retrieving them later for generating directions to a destination.

I found the answer in the post below to be helpful in explaining how to generate directions, but I don't know how to go about turning my latitude & longitude doubles back into a MKMapItem. Is this something that can be done?

is there a way to get directions in mkmapview using a built in apple API?

Community
  • 1
  • 1
Adrian
  • 16,233
  • 18
  • 112
  • 180
  • 1
    do you have a problem with initing it by Placemark? because you can do it via: `–initWithPlacemark:`. – holex Mar 16 '15 at 14:49
  • Like this?--> http://stackoverflow.com/questions/12692924/mkmapitem-with-specific-location – Adrian Mar 16 '15 at 14:51

1 Answers1

1

@holex pointed me in the right direction for a solution. Turning latitude/longitude coordinates from Core Data into a MKMapItem can be accomplished with the following code:

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([self.destinationLatitude doubleValue], [self.destinationLongitude doubleValue]) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:@"Name of your location"];
Adrian
  • 16,233
  • 18
  • 112
  • 180