Tag: mkannotation

如何使自定义MKAnnotation可拖动

我需要MKAnnotation与不同的引脚图像。 所以我创造了以下: @interface NavigationAnnotation : NSObject <MKAnnotation> – (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate; … @interface NavigationAnnotation () @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *address; @property (nonatomic, assign) CLLocationCoordinate2D theCoordinate; @end @implementation NavigationAnnotation – (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate { if ((self = [super init])) { if ([name isKindOfClass:[NSString class]]) { self.name = name; } else { […]

当轻击MKAnnotation时,防止MKMapView上的触摸事件被检测到

我有一个UITapGestureRecognizer,当用户点击Map时,它会隐藏和显示我的MKMap上的一个工具栏。 但是,当用户点击MKMapAnnotation时,我不希望地图以正常方式(上图)响应水龙头。 此外,当用户点击地图上的其他地方取消select一个MKAnnotation标注,我也不希望工具栏响应。 所以,只有在当前没有选定状态的MKAnnotations时,工具栏才会响应。 当用户直接点击注释时也不应该回应。 到目前为止,我正在尝试对地图上的轻拍手势做出反应的以下操作 – 但注释视图永远不会被检测到(第一个if语句),而且无论此方法如何,注释视图也会启动。 -(void)mapViewTapped:(UITapGestureRecognizer *)tgr { CGPoint p = [tgr locationInView:self.mapView]; UIView *v = [self.mapView hitTest:p withEvent:nil]; id<MKAnnotation> ann = nil; if ([v isKindOfClass:[MKAnnotationView class]])<—- THIS CONDITION IS NEVER MET BUT ANNOTATIONS ARE SELECTED ANYWAY { //annotation view was tapped, select it… ann = ((AircraftAnnotationView *)v).annotation; [self.mapView selectAnnotation:ann animated:YES]; } […]

didAddAnnotationViews不工作在MKMapView

我一直在玩MKMapView,并试图解决MKMapViewDelegate系统如何工作。 到目前为止,我没有运气在添加当前位置标记时调用didAddAnnotationViews。 我已经设置了我的应用程序委托来实现MKMapViewDelegate,我有一个Outlet到我的xib中的MapView,并设置MapView的委托属性为self,就像在应用程序委托实例中一样。 我已经在应用程序委托中实现了didAddAnnotationViews,我只需NSLog对它的任何调用,如下所示。 地图被设置为显示当前位置,并在启动时添加蓝色引脚注释,但由于某些原因,AddAnnotationViews未被命中。 – (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{ NSLog(@"Annotation added!"); } 任何想法,我可能错过了?

如何创build一个NSMutableArray并为其指定一个特定的对象?

我只是进入Obj C,我正在创build一个MKAnnotations数组。 我已经创build了名为TruckLocation的MKAnnotation类,它包含名称,描述,纬度和经度。 这是我迄今为止的数组: NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: @[<#objects, …#>] nil];

为当前位置注释设置canShowCallOut = NO

我为当前位置图标使用自定义调用(标题和副标题)。 我试图closures默认注释,但它不起作用。 – (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation { NSLog(@"viewForAnnotation"); if ([annotation isKindOfClass:[MKUserLocation class]]) { MKAnnotationView *userLocationView = [mapView viewForAnnotation:annotation]; userLocationView.canShowCallout = NO; NSLog(@"[annotation isKindOfClass:[MKUserLocation class]"); return nil; } } 唯一的办法是 -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)ann { if([ann.annotation isKindOfClass:[MKUserLocation class]] ) { [mymap deselectAnnotation:ann.annotation animated:NO]; } } 但它有时滞后。 有没有其他的方法来禁用当前位置注释的默认标注视图? 任何帮助将不胜感激。

在表格视图中从选定的行打开地图注释

我有一个类的地图视图与我所有的标题和字幕的注释。 有一个导航栏button,显示所有这些标题和字幕的列表。 我希望能够在表格视图中select一行,并在地图视图中打开具有相同标题的注释。 任何帮助? 我现在唯一的问题是获取地图视图打开时显示的注释。 我知道我需要使用selectAnnotation:animated:但是我很难弄清楚如何告诉它打开匹配标题的注释。 在RSFM(名为worldView的地图视图类)我显示这样的表视图: – (void)showList { List *list = [[List alloc] initWithNibName:nil bundle:nil]; list.annotations = [[NSArray alloc]initWithArray:worldView.annotations]; list.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self.navigationController pushViewController:list animated:YES]; } 这是我在我的表视图中的didSelectRowAtIndexPath方法到目前为止: – (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { RSFM *rsfm = [[RSFM alloc] initWithNibName:nil bundle:nil]; NSLog(@"List Annotations Array Count: %d", [annotations count]); UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; NSString […]

Swift – 将圆angular设置为注释视图图像

这是我以前的线程,我把图像设置为注释视图引脚 Swift – 将arrays中的不同图像设置为注释引脚 现在我遇到了在注解视图图像上设置圆angular的问题。 cannot show callout with clipsToBounds enabled swift 似乎我必须select圆angular或显示标注,我真的不明白为什么这两个不能来。 有没有办法做到这一点? 这里是我的viewForAnnotation函数: func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if !(annotation is RestaurantAnnotation) { return nil } let reuseId = "restaurant" var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) if anView == nil { anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) anView.canShowCallout = false } […]

只旋转视图而不旋转其子视图

有没有什么办法可以将视图变换转换为子视图? 我有一个自定义的MKAnnotationView,根据用户的标题值旋转。 在自定义Annotation视图类的下面的方法中,我将一个子视图添加到注释视图。 – (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if(selected) { [self addSubview:self.myCallOutView]; return; } [self.myCallOutView removeFromSuperview]; } 但问题是当我的注释视图旋转,然后我select任何注释,myCallOutView也出现旋转,我不想要的。 我正在旋转自定义注释视图使用下面的行 [self setTransform:CGAffineTransformMakeRotation(angle * M_PI / -180.0)]; 我怎样才能避免这种情况? 我需要在myCallOutView上应用一些转换,然后将其添加为子视图吗?

MapView自定义图钉问题

我已经改变了我的MapView引脚图像,但我得到这个问题,一些点不会改变引脚图像,其中一些改变。 问题在哪里? 我已经添加了一个例子。 我的代码: – (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *pinAnnotation = nil; MKAnnotationView *pinView = nil; if(annotation != locationMap.userLocation) { static NSString *defaultPinID = @"myPin"; pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinAnnotation == nil ) pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; pinAnnotation.canShowCallout = YES; pinAnnotation.animatesDrop = YES; pinAnnotation.enabled = YES; […]

引脚在地图上放置时,在注释中显示地址

目前我可以在地图上放置别针。 现在我想让注解标题显示引脚被丢弃的地址。 我已经看了这个,但不能让我的工作: 将标注的标题设置为当前地址 代码在我的ViewController.m 更新。 – (void)addPinToMap:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return; CGPoint touchPoint = [gestureRecognizer locationInView:self.map]; CLLocationCoordinate2D touchMapCoordinate = [self.map convertPoint:touchPoint toCoordinateFromView:self.map]; CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude]; [self.geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemark, NSError *error) { //initialize the title to "unknown" in case geocode has failed… NSString *annTitle = @"Address unknown"; […]