s.calin
s.calin

Reputation: 83

Navigate to annotation location on MKMapView

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???

Upvotes: 0

Views: 1317

Answers (1)

s.calin
s.calin

Reputation: 83

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

Upvotes: 2

Related Questions