1

What I want to do is allow the user to open Apple Maps and have it automatically open the Directions form for them to get directions to my location.

The destination is a Latitude/Longitude pair. I am doing this:

NSString *addressString = @"http://maps.apple.com/?daddr=50.894967,4.341626&dirflg=d";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];

This opens Apple Maps as I expect. However, in the destination field, it shows the Latitude/Longitude pair. I would like to specify this label. Here is what I mean:

enter image description here

Is there anyway I can replace the coordinates with a label using URL params?

Thanks!

Community
  • 1
  • 1
user1282637
  • 1,827
  • 5
  • 27
  • 56
  • I'm sorry, I don't really understand what want to achieve. Could you explain it some more? – joern Oct 18 '15 at 16:31
  • @joern in the screenshot, the "End:" field automatically populates to "50.894967, 4.341626" but I want to be able to specify some other text to go into this field (the name of the location I am navigating the user to) – user1282637 Oct 18 '15 at 21:15

3 Answers3

0

You can use Core Location to get the current location and after you can set your "Start" point with that info. You don't have to set "End" point.

Please check this link, I'm sure you'll find its useful;

How to invoke iPhone Maps for Directions with Current Location as Start Address

Community
  • 1
  • 1
Göktuğ Aral
  • 1,409
  • 1
  • 13
  • 28
0

This might not be the way you want. But it give us more flexibility to open the Map app. That is using [MKMapItem openMapsWithItems:launchOptions:] to ask the Map to open the address. The screen looks a bit different from what you might expect though.

CLLocation* location = [[CLLocation alloc] initWithLatitude:50.894967 longitude:4.341626];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 10000, 10000);
NSDictionary *addressDict = @{
        (NSString *) kABPersonAddressStreetKey : @"Any Name",
};
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:addressDict];
MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];

[destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];

[MKMapItem openMapsWithItems:@[destinationMapItem]
               launchOptions:@{
                       MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                       MKLaunchOptionsMapSpanKey : [NSValue valueWithMKCoordinateSpan:region.span]
               }
];

enter image description here

thanyaj
  • 302
  • 1
  • 6
0

Just use core location for current location, and start, no end needed though

Sidsy
  • 161
  • 2
  • 3
  • 11