内容简介:翻译自:https://stackoverflow.com/questions/6078357/show-users-location-blue-point-in-iphone-mkmapview
我正在我的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告诉地图视图为其绘制默认视图,即蓝点.
您也可以删除这些行,因为它们将不再需要:
if ([[annotation title] isEqualToString:NSLocalizedString(@"Current Location",@"")]) { MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease]; //pin.pinColor = MKPinAnnotationColorRed; annotationView = pin; } else
翻译自:https://stackoverflow.com/questions/6078357/show-users-location-blue-point-in-iphone-mkmapview
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Vue scrollBehavior 滚动行为,实现后退页面显示在上次浏览的位置
- css – 位置:粘不起作用
- 画解算法:35. 搜索插入位置
- Ceph根据Crush位置读取数据
- Ceph根据Crush位置读取数据
- iOS后台模式借助位置更新实现
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。