0
votes

I create a UITextView and set text=@"中国,浙江省杭州市滨江区", set dataDetectorTypes=UIDataDetectorTypeAddress, then,long pressed, choose open map, it can found the address in GoogleMap.

But, the same address, i used openUrl can't find the address.

NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

anybody who can tell me why? or iOS not use this url(http://maps.google.com/maps?q=%@)

2

2 Answers

0
votes

Would you try with a different enconding? eg., NSUnicodeStringEncoding

 NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", [address stringByAddingPercentEscapesUsingEncoding:NSUnicodeStringEncoding]]; 

And what is the result of

[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

?

0
votes

Google Maps http:// calls don't use % seperators but rather +'s.

NSString *fixedAddress = [fullAddress stringByReplacingOccurencesOfString:@" " withString:@"+"];
NSString *googleCall = @"http://maps.google.com/maps?q=";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[googleCall stringByAppendingString:fixedAddress]]];

I, myself encountered this issue and fixed it with the preceeding code last night.