我有一个使用iphone地图套件的应用程序。它显示了一组标准引脚。 现在我切换到引脚的自定义图像(使用MKMapViewDelegate)
问题是自定义引脚不在右侧 - 自定义引脚指向原始位置附近。
问题是iphone如何使用自定义引脚。例如:让我们有50x50像素的图像。我们有全局坐标(long,lat):XY
iphone中心图片如何?
谢谢
答案 0 :(得分:9)
如果将自定义图像指定给图像属性。显示注释时,图像将以目标地图坐标为中心显示。如果您不希望图像在地图坐标上居中,则可以使用centerOffset属性在任何方向上水平和垂直移动中心点。
因此,自定义图片仅显示在目标坐标的中心。
MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"MyCustomAnnotation"] autorelease];
aView.image = [UIImage imageNamed:@"myimage.png"];
aView.centerOffset = CGPointMake(10, -20);
答案 1 :(得分:6)
解决方案是在mapView的委托中设置中心偏移量,并在注释视图中设置不:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* const kPinIdentifier = @"pinidentifier";
PinAnnotationView* customPinView = [[[PinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:kPinIdentifier] autorelease];
customPinView.canShowCallout = NO;
// Here !!
customPinView.centerOffset = CGPointMake(0, -21.5f);
return customPinView;
}