如何使地图钉(自定义)图像出现在中心点
请让我知道如何使图像显示在中心点。 让我详细说明。 我有MapPin自定义图像,但图像看起来是这样的如何使地图钉(自定义)图像出现在中心点
如果你仔细看的话,针落在正确的纬度和长,但图像的中心是是圆形部分落在拉特和长。由此拉长似乎是在不同的位置(见针基)。 但是,我们想要的是针脚落在该位置(纬度和长度)。 像这样的东西..(请参阅第二张图片) 请不要告诉我改变图像的高度和宽度,因为有300张图像。 除非和直到这是唯一的选择,或者我可以通过编程来改变它。
请帮助这个可悲的问题。
谢谢你好朋友。
您可以使用centerOffset根据图像大小移动位置。
例如与绝对偏移量:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString* const annIdentifier = @"annotationidentifier";
PinAnnotationView* myPinView = [[[PinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annIdentifier] autorelease];
myPinView.centerOffset = CGPointMake(0, -10.0f);
return myPinView;
}
根据您的个人图像大小用计算值替换这些绝对值。
我在一个测试应用程序做这样的事情。
我把这段代码放在这里,你可以自己定制它,我希望这会帮助你。
在超级视图没有负载,我有
MapAnnotation *安= [[MapAnnotation的alloc] INIT];
MKCoordinateRegion region;
region.center.latitude = 31.504679;
region.center.longitude = 74.247429;
region.span.latitudeDelta = 0.01;
region.span.longitudeDelta = 0.01;
[mapView setRegion:region animated:YES];
ann.title = @"Digital Net";
ann.subtitle = @"Office";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
iOS学习者:我尝试使用该区域作为所有引脚通用的区域,并在添加引脚后将其设置为映射。但不幸的是...没有工作。 – iCodeAtApple
你找到解决方案还是存在问题 –
iOS学习者:我确实找到解决方案,请检查上面的评论,所以我接受你的答案。 – iCodeAtApple
在viewForAnnotation中,是否正确设置'centerOffset'?请参阅http://*.com/questions/13492231/change-the-images-origin-of-map-annotation-view。 – Anna
@AnnaKarenina:链接帮助我达到了很大的程度。但不幸的是我无法获得正确的纬度/长度的引脚。 我是否需要针对每个针脚有不同的centerOffset,因为我有4个针脚,同时应用centerOffset,它似乎只适用于单个针脚而不是所有针脚。 – iCodeAtApple
@AnnaKarenina:终于!!!我为每个引脚使用了不同的偏移量。尽管准确放置每个引脚花费了我很长时间,但最终我实现了它。由于MichaelO发布了答案,我会接受他的。 但我不能否认安娜卡列尼娜的评论在很大程度上有帮助,所以我在她发布的链接上投了她的答案。 非常感谢你们。 ! – iCodeAtApple