0

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=%@)

avincross
  • 11
  • 4

2 Answers2

0

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]

?

sergio
  • 68,819
  • 11
  • 102
  • 123
  • Hi, NSUnicodeStringEncoding is not work, it's garbled, just like this "http s://maps.google.com/maps?q=ÿþ-NÿþýV,ÿþYmÿþ_lÿþ+w,ÿþm..." – avincross Jun 28 '12 at 09:27
  • and what is `[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]`? – sergio Jun 28 '12 at 09:57
  • it show normal, no garbled, and when i don't use any Encoding, openUrl don't do any operate. – avincross Jun 29 '12 at 02:00
  • I tried your code with OpenURL and it works, correctly opening the Maps application on Binjiang. Are you sure that text and address have the same content, in your code above? – sergio Jun 29 '12 at 07:01
  • the example is short than address in my app. it's 浙江省杭州市滨江区南环路4280号元光德大厦5楼502室. The same address in UITextView with UIDataDetectorTypeAddress can be found in GoogleMap, but not works with OpenURL.(You could copy the chinese and try it) – avincross Jun 29 '12 at 07:24
  • I tried the address with OpenURL and in Safari OSX, and it did not work. The only part of the address that is recognized by google maps is: 浙江省杭州市滨江区南环路4280号. Is it possible that UITextView just trims the full string somewhere? – sergio Jun 29 '12 at 07:38
0

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.

Giz
  • 199
  • 1
  • 15