Как я могу сделать значок предварительного просмотра, например, в приложении iPhone Map?
Снимок экрана http://img835.imageshack.us/img835/1619/img0016x.png
Есть ли функция для этого?
В iOS 7 используйте MKMap Snapshotter. Из NSHipster :
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.region = self.mapView.region;
options.size = self.mapView.frame.size;
options.scale = [[UIScreen mainScreen] scale];
NSURL *fileURL = [NSURL fileURLWithPath:@"path/to/snapshot.png"];
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) {
NSLog(@"[Error] %@", error);
return;
}
UIImage *image = snapshot.image;
NSData *data = UIImagePNGRepresentation(image);
[data writeToURL:fileURL atomically:YES];
}];
Прежде чем iOS7 выполните одно из следующих действий:
Apple's deal with Google is more reliable than a free API, but on the bright side, it is really simple. Documentation is at http://code.google.com/apis/maps/documentation/staticmaps/
This is the minimum amount of parameters for practical use: http://maps.googleapis.com/maps/api/staticmap?center=40.416878,-3.703530&zoom=15&size=290x179&sensor=false
Краткое описание параметров:
center
: this can be an address, or a latitude,longitude pair with up to 6 decimals (more than 6 are ignored).format
: png8 (default), png24, git, jpg, jpg-baseline.language
: Use any language. Default will be used if requested wasn't available.maptype
: One of the following: roadmap, satellite, hybrid, terrain.scale
: 1,2,4. Use 2 to return twice the amount of pixels on retina displays. 4 is restricted to premium customers.
Non paid resolution limits are 640x640 for 1 and 2.sensor
: true or false. Mandatory. It indicates if the user is being located using a device.size
: size in pixels.zoom
: 0 (whole planet) to 21.Есть еще несколько, чтобы добавить многоугольники, пользовательские маркеры и стиль карты.
NSData* data = [NSData dataWithContentsOfURL:@"http://maps.googleap..."];
UIImage *img = [UIImage imageWithData:data];
Вы можете использовать Google Maps Static API для создания образа вместо загрузки всего <код> UIMapView .