user836026
user836026

Reputation: 11350

How to make link open "Maps" window when clicked

I would like to have a link in a web page in such a way that when the link is clicked it opens the standard "Maps" view in iPhone.

If such a thing is possible, what tag format do I need to use with the link?

Upvotes: 0

Views: 404

Answers (2)

rohan-patel
rohan-patel

Reputation: 5782

I used this code which works passing longitude lattitude:

 NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",cur_lat, cur_lon,[loc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"current %f %f",cur_lat,cur_lon);

[[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]];

Upvotes: 1

yuji
yuji

Reputation: 16725

It's pretty simple; you don't even need to use a specific scheme identifier. Any Google Maps URL will be opened with the Maps app automatically, as long as all the parameters are supported.

So links like these:

http://maps.google.com/maps?q=cupertino
http://maps.google.com/maps?daddr=San+Francisco,+CA&saddr=cupertino

Would automatically be opened in Maps. To find out more about what works and what doesn't see the Map Links page from the Apple URL Scheme Reference.

Upvotes: 2

Related Questions