gpt4 book ai didi

iphone - 在 iPhone MKMapView 中显示用户位置蓝点

转载 作者:可可西里 更新时间:2023-11-01 03:05:20 31 4
gpt4 key购买 nike

我正在我的 iPhone 应用程序的 MapView 中开发自定义图钉。这是代码:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id  <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";

MKAnnotationView *annotationView = (MKAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}

if ([[annotation title] isEqualToString:NSLocalizedString(@"Current Location",@"")]) {

MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
//pin.pinColor = MKPinAnnotationColorRed;
annotationView = pin;
}
else
{
NSString *pin = [NSString stringWithFormat:@"pin%i.png",[[annotation imgNumber] intValue]];
annotationView.image = [UIImage imageNamed:pin];//Canviar la chincheta per numero
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[annotationView setRightCalloutAccessoryView:button];
annotationView.annotation = annotation;
annotationView.canShowCallout = YES;

/********* Imagen a la izquierda en la burbuja *********/
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// Set up the Left callout
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

// Set the image for the button
//[myDetailButton setImage:[UIImage imageNamed:@"botocorreu.png"] forState:UIControlStateNormal];
NSString *detailButton = [NSString stringWithFormat:@"%i",[[annotation imgNumber] intValue]];
[myDetailButton setImage:[UIImage imageNamed:detailButton] forState:UIControlStateNormal];
// Set the button as the callout view
annotationView.leftCalloutAccessoryView = myDetailButton;
annotationView.canShowCallout = YES;
}
return annotationView;
}

这很好用,但用红色图钉显示用户位置。我检查了 IB 中的“显示用户位置”。我想使用默认的蓝点,它会在用户移动时自动移动,对吗?我该怎么做?

非常感谢。

最佳答案

将此添加到 viewForAnnotation 方法的顶部:

if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;

特殊的用户位置注释是 MKUserLocation 类型,在这种情况下返回 nil 会告诉 map View 为其绘制默认 View ,即蓝点。

您还可以删除这些行,因为它们将不再需要:

if ([[annotation title] isEqualToString:NSLocalizedString(@"Current Location",@"")])  {
MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
//pin.pinColor = MKPinAnnotationColorRed;
annotationView = pin;
}
else

关于iphone - 在 iPhone MKMapView 中显示用户位置蓝点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6078357/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com