0

I am developing an iOS app . Within this app i have a type of view which among other information presents a MKMapView map to the currently selected company store; the store's location is plotted on the map through a pin. The pin has a customized MKAnnotationView, in which i have added a detail disclosure button. What i want to do is when the user presses the button, to present a popover with some choices - like go to the website of that specific store.

One of the options that i want to implement there is to navigate from the user's current location to the location of the store. What i want the application to do is present an obtion which should say smith. like "Navigate to location" , which when clicked opens GoogleMaps, selects the navigate to location options, selects CurrentLocation as "Start" and the store's location stored in the pin' coordinates as "End". Can this be done , because i haven't found a solution to this ? If so, how???

s.calin
  • 83
  • 1
  • 9
  • Have a look at http://stackoverflow.com/questions/30058/how-can-i-launch-the-google-maps-iphone-application-from-within-my-own-native-ap and find out which parameters you need to provide for your action. – anka Aug 15 '12 at 11:36
  • And also have a look at https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html – anka Aug 15 '12 at 11:38

1 Answers1

2

I did it with this code:

- (void) openBrowser:(id)sender
{ 
    NSString *launchUrl=@"";
    launchUrl= [launchUrl stringByAppendingString:@"http://maps.google.com/maps?daddr="];
    NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", self.newRegion.center.latitude];
    NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", self.newRegion.center.longitude];
    NSString *llat=[tmpLat stringByAppendingString:[@"," stringByAppendingString:tmpLong]];
    launchUrl=[@"http://maps.google.com/maps?daddr=" stringByAppendingString:llat];
    launchUrl=[launchUrl stringByAppendingString:[@"&saddr=" stringByAppendingString:@"Current Location"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[launchUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}

openBrowser is a method I call with the detail disclosure button. I found the urls that point to maps.google.com are handled by default by the google maps app installed on the phone; for directions from point A to point B the url must be something like:

http://maps.google.com/maps?daddr=whatever&saddr=whatever

daddr= Destination

saddr= Source

Rüdiger Hanke
  • 6,215
  • 2
  • 38
  • 45
s.calin
  • 83
  • 1
  • 9