4

I'm trying to show routes of two places with Apple's Map.

For the two places, I have both names and coordinates.

MKMapItem *currentLocation = [[MKMapItem alloc]
  initWithPlacemark:[[MKPlacemark alloc]
                        initWithCoordinate:paramModel.fromCoordinate2D
                     addressDictionary:nil]];
MKMapItem *toLocation = [[MKMapItem alloc]
  initWithPlacemark:[[MKPlacemark alloc]
                        initWithCoordinate:paramModel.toCoordinate2D
                         addressDictionary:nil]];
return [MKMapItem openMapsWithItems:@[ currentLocation, toLocation ]
                    launchOptions:@{
                      MKLaunchOptionsDirectionsModeKey :
                          MKLaunchOptionsDirectionsModeDriving
                    }];

The names are stored inside the paramModel.

I assume this can be achieved by using addressDictionary? I tried kABPersonAddressStreetKey and kABPersonAddressCityKey, but neither will show up in the final route view.

xi.lin
  • 3,326
  • 2
  • 31
  • 57

2 Answers2

0

Just find out that I can modify the name field of MKMapItem directly.

MKMapItem *currentLocation = [[MKMapItem alloc]
  initWithPlacemark:[[MKPlacemark alloc]
                    initWithCoordinate:paramModel.fromCoordinate2D
                 addressDictionary:nil]];
currentLocation.name = paramModel.fromName;
xi.lin
  • 3,326
  • 2
  • 31
  • 57
-4

Try creating your MKPlacemark as a variable and then modifying the title field on that variable like so:

MKPlacemark* placemark = [[MKPlacemark alloc]
                    initWithCoordinate:paramModel.fromCoordinate2D
                 addressDictionary:nil]];
placemark.title = @"Some Title";
placemark.subtitle = @"Some subtitle";

Then set the variable as the parameter in your map item constructor.