DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Open Google Map And Point To A Location Specified By Its Coordinates

  • submit to reddit
        Coordinates were obtained from CLLocationManager. Open Google Map and point to that location.

	CLLocationCoordinate2D loc = [newLocation coordinate];
	latitude.text = [NSString stringWithFormat: @"%f", loc.latitude];
	longitude.text	= [NSString stringWithFormat: @"%f", loc.longitude];
	altitude.text = [NSString stringWithFormat: @"%f", newLocation.altitude];
	NSString *mapUrl = [NSString stringWithFormat: @",%f", loc.latitude, loc.longitude]; 
	NSURL *url = [NSURL URLWithString:mapUrl]; 
	[[UIApplication sharedApplication] openURL:url]; 

More examples. If you want to show all Thai restaurants, you could do:
NSString *name = @"thai";

NSString *latlong = @”-33.874559,151.219575″;

NSString *url = [NSString stringWithFormat: @"",
                             [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                             [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

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

You can also set zoom level with "z" flag. (1-19, default 17)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];

It's also possible to place custom pins on the map by using a KML (Keyhold Markup Language) file:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];