0

Maybe a dum question but I want to know how to set the latitude and longitude from a selected Annotation to a string so it will be useful for the Maps navigation. I've already found a way to use the UserLocation for the source address.

This is what I got so far:

myAnn = [[Annotations alloc]init];
    location.latitude = 52.338847;
    location.longitude = 4.937482;
    myAnn.coordinate = location;
    myAnn.title = @"My Title";
    myAnn.subtitle = @"Rozenburglaan 1";

CarClicked is a method I use when the user touches the BlueCar Icon inside the selected Annotation:

- (void)carClicked {

    myMapView.showsUserLocation = YES;

    NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=cupertino", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}

So the urlString certainly will be: @"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f" What is the best way to set the daddr=%f,%f with the selected annotation? Many thanks

SwingerDinger
  • 276
  • 1
  • 7
  • 21
  • you should check it first with [[UIApplication sharedApplication] canOpenURL], so if url is invalid , you can show a alert. else you are doing it correclty. – Pawan Rai May 06 '14 at 19:37
  • I want to navigate from the users location to the selected Annotation. How can I set the longitude and latitude in the stringWithFormat? – SwingerDinger May 06 '14 at 21:58
  • 1
    Is the BlueCar icon an accessory button in the annotation's callout? If so, it would be much easier to use the calloutAccessoryControlTapped delegate method and in there the selected annotation's coordinate is view.annotation.coordinate. If you must use a custom method, you can get a reference to the selected annotation using the map view's selectedAnnotations array. See http://stackoverflow.com/questions/9797047/how-to-keep-data-associated-with-mkannotation-from-being-lost-after-a-callout-po?lq=1 for an example. –  May 06 '14 at 23:01
  • Fixed it Anna. Thanks again for your awesomeness help! – SwingerDinger May 07 '14 at 08:41

0 Answers0