0

I'm trying to use NSURL to send the user to maps with a address from my db. And I want to do this in an action within a UIButton, like I do for tel, mail and web. Like this;

- (IBAction)restActionWeb:(UIButton *)sender {
NSString *urlString = [NSString stringWithFormat:@"http://%@",[restDetails objectForKey:@"Web"] ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

}

Is it possible to to this for a streetaddress like "123 My Road, MyTown, CA 95472, USA"?

Tried this in some variations without any luck;

- (IBAction)restActionFind:(UIButton *)sender {
// Merge street + zip
NSMutableString *tempAdress = [NSMutableString string];
[tempAdress appendString:@"address://"];
[tempAdress appendFormat:@"%@",[restDetails objectForKey:@"Street"]];
[tempAdress appendFormat:@", %@",[restDetails objectForKey:@"Zip"]];
[tempAdress appendFormat:@", %@",[restDetails objectForKey:@"City"]];
[tempAdress appendFormat:@", USA"]; // Have this limitation in future?
self.restFindLabel.text = tempAdress;

// CHECK don't work, whats the url schema for address?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tempAdress]];

}

Would like it to work just like when you have en address detected in some textfield that you clic on and then go into maps with that address and show it.

I think it would be an "overkill" to use plan B: Use CoreLocation + sending address that way. And it also draws on the battery. I mean, I alread have the address in my dB and just want Maps to show it.

ANY suggestions or tips on this? THANKS! :-)

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Mac
  • 111
  • 1
  • 11
  • See http://stackoverflow.com/questions/12504294/programmatically-open-maps-app-in-ios-6 – peterept Nov 09 '12 at 13:55
  • Some really good info in the link regarding this. Thank's. whish I could give out two Answers correct, here's a symbolic one for you anyway: **√** ;-) – Mac Nov 09 '12 at 15:22

1 Answers1

0

Have you tried this?

NSString *stringURL = @"http://maps.google.com/maps?q=123+My+Road,+MyTown,+CA+95472,+USA"];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

This means using the http:// scheme instead of address:// and relying on the OS to understand it'a map. Possibly will not work well on iOS6, but it should on iOS5.

(source)

sergio
  • 68,819
  • 11
  • 102
  • 123
  • Thank's, didn't think about that one. Will do this as a work-around for now. About iOS6 - yes need to prepare for that too in the app, some nice info about it on the above link in comments... – Mac Nov 09 '12 at 15:26
  • 1
    In iOS 6, just change `maps.google.com` to `maps.apple.com` to send it to Apple maps – Stephanie Apr 02 '13 at 15:02