3

To open Google Maps with directions, i'm using a formatted NSString inside a NSURL. But it doesn't work with [[UIApplication sharedApplication] openURL:nsurl];

code:

NSString * directionsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%@&saddr=%@", @"Hartenseweg 16, Renkum", @"1 Infinte Loop, Cupertino"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:directionsURL]];
Joost
  • 113
  • 1
  • 6
  • possible duplicate of [URLWithString: returns nil](http://stackoverflow.com/questions/1981390/urlwithstring-returns-nil) – Mike Abdullah Apr 14 '13 at 18:01

1 Answers1

2

You need to use [NSString stringByReplacingPercentEscapesUsingEncoding:] to ensure you get a properly encoded string for a url.

TechZen
  • 64,370
  • 15
  • 118
  • 145