1

我一直在尝试实现一个 UIMapView 图标,就像这张图片中的那样。有人知道这个应用程序是如何创建缩略图的吗?

编辑

尝试使用以下代码实现这一点:

CLLocationCoordinate2D restaurantLocation = CLLocationCoordinate2DMake(Latitude, Longitude);
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(restaurantLocation, 1000, 1000);

_mapView.region = region;
_mapView.hidden = NO;

_annotation = [[MKPointAnnotation alloc] init];
_annotation.coordinate = restaurantLocation;
//annotation.title = _restaurantInformation 

[_mapView addAnnotation:_annotation];


UIGraphicsBeginImageContext(_mapView.frame.size);
[_mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGSize newSize;
newSize.width = 50; // any width u want
newSize.height= 80; // any height u want
UIGraphicsBeginImageContext(newSize);
[mapImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
_mapThumbnail.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

在此处输入图像描述

4

2 回答 2

1

此代码用于显示特定位置的缩略图及其对我有用

NSString *staticMapUrl = [NSString stringWithFormat:@"http://maps.google.com/maps/api/staticmap?markers=color:red|%f,%f&%@&sensor=true",lat, log,@"zoom=10&size=114x116"];
NSURL *mapUrl = [NSURL URLWithString:[staticMapUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:mapUrl]];
[imgViewClue setImage:image];
于 2012-08-04T06:22:07.937 回答
1

Mapview 中带有位置的注释应位于中心。现在

UIGraphicsBeginImageContext(mapView.frame.size);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

用于创建 mapImage 的缩略图调整大小

CGSize newSize;
newSize.width = 50; // any width you want
newSize.height= 80; // any height you want
UIGraphicsBeginImageContext(newSize);
[mapImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
UIImage* thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

另一种方式是

你可以试试谷歌静态地图 API

这是示例代码

NSString *urlString = @"http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=200x200&sensor=false";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *thumbnail= [UIImage imageWithData:data];
[yourImageView setImage:thumbnail];

通过这个你可以得到基于你的坐标的静态图像。

于 2012-06-30T18:15:29.503 回答