written by Christian Corsano
,
Tuesday May 06, 2008 at 02:39:52 PM - GMT
This is the first post of a serie in which I will present some useful (and often trivial) stuff I’m implementing in Cocoa for my (hopefully) upcoming app.
The basic idea is to present short snippets of code to do something.
In this case, to get a Google Static Map representing the world (but could be refactored easily to customize the view) in an NSImage object.
The code is available on the full post.
- (NSImage*) worldMapWithSize:(NSSize) size
{
NSImage* result = [NSImage alloc];
size.width = size.width > 512 ? 512 : size.width;
size.height = size.height > 512 ? 512 : size.height;
NSMutableString* urlString = [NSMutableString stringWithString:@"http://maps.google.com/staticmap?"];
[urlString appendString:@"zoom=1"];
[urlString appendString:@"¢er=0,0"];
[urlString appendString:@"&size="];
[urlString appendString:[[NSNumber numberWithInt:size.width] stringValue]];
[urlString appendString:@"x"];
[urlString appendString:[[NSNumber numberWithInt:size.height] stringValue]];
[urlString appendString:@"&key="];
[urlString appendString:[self googleMapsAPIKey]];
[result initWithContentsOfURL:[NSURL URLWithString:urlString]];
return result;
}