Tag: mkannotationview

可拖动的Pin在地图上没有固定的位置

目前我正在实现一个function,用户可以在地图上手动更正一个引脚。 我已经将annotationView设置为annotationView.draggable = YES; 我也实现了委托方法来接收新的坐标。 但是现在我怎么能告诉mapView拖动动作现在应该停止,并且在地图上固定位置,即使地图被移动了。 目前的行为是,在将引脚拖动到新的位置之后,如果我然后移动地图,则引脚在设备屏幕上具有固定的位置,但不在地图上。 帮助表示赞赏:)。 代表: – (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateEnding) { CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate; NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude); } }

根据所选的MKAnnotationViewdynamic更改leftCalloutAccessoryView

我有一个图像arrays,与我的地图上的每个Annotation相关联。 我可以静态添加一个图像到leftCalloutAccessoryView但我不确定如何使这个dynamic。 我希望它清楚我所要求的。 每个注释都有我自己想要显示的独立图像,但是我不确定如何用下面的方法引用图像。 – (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation { if([annotation isKindOfClass:[MKUserLocation class]]) return nil; NSString *annotationIdentifier = @"PinViewAnnotation"; MyAnnotationView *pinView = (MyAnnotationView *) [mv dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; if (!pinView) { pinView = [[MyAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier]; pinView.canShowCallout = YES; UIImageView *houseIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];//static image [houseIconView setFrame:CGRectMake(0, 0, 30, 30)]; pinView.leftCalloutAccessoryView = houseIconView; […]

为iOS设置dynamic地图引脚颜色

我parsing一个包含string0,1和2的xml。 //参考0 =绿色1 =红色2 =紫色 我有一个类,确认MKAnnotaion包含下面的variables属性。 CLLocationCoordinate2D coordinate; NSString *title; NSString *subtitle; MKPinAnnotationColor pinColor; 这个类被命名为MyAnnotation 现在在地图视图的viewDidLoad中,我运行一个for循环来遍历parsing的数据,如下所示(locationArray拥有这个数据,我把所有的信息都拉出来了。 for (int i = 0; i < locationArray.count; i++) { myAnnotation =[[MyAnnotation alloc] init]; NSString *thePointName = [[locationArray objectAtIndex:i]xmlName]; NSString *theAddress = [[locationArray objectAtIndex:i]xmlAddress]; NSString *latString = [[locationArray objectAtIndex:i]xmlLat]; NSString *lonString = [[locationArray objectAtIndex:i]xmlLon]; //这是拉出所提到的0,1或2个string的string,它们代表了引脚的颜色。poinType保留为一个string pointType = [[locationArray objectAtIndex:i]xmlType]; […]

每个引脚不同的自定义图像

这可能听起来像一个普遍的问题,但我只find答案,如果我想我所有的针脚相同的图像,我不知道。 这就是我现在正在工作: 我有我所有的位置在一个地点arrays(自定义类与长,拉特,名称,引脚名称)。 在viewdidLoad我循环该数组并创build我的引脚与发现的每个对象,请参阅以下代码: for(int i = 0 ; i<[_locationList count] ; i++) { Location *item = [_locationList objectAtIndex:i]; CLLocationCoordinate2D coordinate; coordinate.latitude = item.locationLatitude; coordinate.longitude = item.locationLongitude; NSString *title = item.locationName; CustomAnnotation* ann = [CustomAnnotation new]; ann.name = title; ann.coordinate = coordinate; ann.pinName = [NSString stringWithFormat:@"pin%i.png",item.idPin]; [self.map addAnnotation:ann]; } 这非常简单,部分来自CustomAnnotation类,它是以下代码: @interface CustomAnnotation : MKPointAnnotation <MKAnnotation>{ […]

自定义地图标注视图隐藏在自来水中

我制作了自定义贴图标注。 我的标注包含UIButtons和UITextView 。 当我点击UIButton ,它很好。 但是,当我点击UITextView它将光标移动到轻击位置,然后取消select引脚和消失标注… 我已经实现了hitTest:withEvent:方法MyAnnotationView像这里: https hitTest:withEvent: //stackoverflow.com/a/13495795/440168 但正如我在日志中看到的, [super hitTest:withEvent:]永远不会返回nil 。 这是我的MyAnnotationView方法: – (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { BOOL isInside = [super pointInside:point withEvent:event]; if (isInside) return YES; for (UIView * subview in self.subviews) { if ([subview isKindOfClass:[NSClassFromString(@"UICalloutView") class]]) continue; CGPoint inPoint = [self convertPoint:point toView:subview]; BOOL isInside = [subview pointInside:inPoint withEvent:nil]; if […]

两次select一个MapView注释

我的iPhone应用程序有一个地图视图与大量的位置,用户可以从中select。 我希望他能够点击其中一个注释来显示其标注视图,然后再实际select它。 问题是didSelectAnnotationView只被调用一次。 那么如何检测已经select的注释? 或者,我怎样才能取消select一个注释,而不隐藏标注视图? 用户可以通过在再次select之前取消select注释来解决这个问题,但这不是直观的,我想避免他必须这样做。

MapKit注解没有显示在地图上

我无法在MapKit的地图上显示MKAnnotationViews。 我正在使用iOS 7,现在已经在论坛和网上search了很多小时,尝试了不同的样本和设置。 下面我有最基本的设置可能(我认为)使其工作。 该应用程序包含一个单独的ViewController,顶部有一个button,剩下的就是MapView。 该button触发方法zoomToUser:(UIBarButtonItem *)发件人。 右键点击并检查我的网点和代表似乎是正确的。 我有一些NSLog语句被触发输出一些debugging信息。 首先是VC: #import "ViewController.h" #import "Data.h" @interface ViewController () <MKMapViewDelegate> @property (weak, nonatomic) IBOutlet MKMapView *mapView; – (IBAction)zoomToUser:(UIBarButtonItem *)sender; @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; self.mapView.showsUserLocation = YES; Data *ann = [[Data alloc] init]; [self.mapView addAnnotation:ann]; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self zoomToUser:nil]; } -(IBAction)zoomToUser:(UIBarButtonItem […]

如何在swift中使用MapKit自定义userLocationAnnotationView图像?

我试图find一种方法来显示使用MapKit的用户在地图上的方向。 本地MapKit的方式,总是旋转整个地图。 由于用户的位置也是一个MKAnnotationView,我决定创build一个特定的类来覆盖它,并使用特定的图像(带箭头)。 class UserLocationAnnotationView: MKAnnotationView { override init(frame: CGRect) { super.init(frame: frame) } override init(annotation: MKAnnotation!, reuseIdentifier: String!) { super.init(annotation: annotation, reuseIdentifier: reuseIdentifier) var frame = self.frame frame.size = CGSizeMake(130, 130) self.frame = frame self.backgroundColor = UIColor.clearColor() self.centerOffset = CGPointMake(-30, -50) } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! } /* // Only override […]

无法将UIImage传递给MKPinAnnotationView

我subclassed MKPointAnnotation并添加一个NSString和一个UIImage所以我可以将这些元素传递给一个MKPinAnnotationView 。 该string传递到MKPinAnnotationView罚款,但图像属性是通过为空。 我无法弄清楚为什么。 我会说有一次在我的手机上运行这个代码的图像出现在一个针一次,所以也许我有一个内存泄漏? 其他1000次我编译的图像在日志中显示为空,并没有出现。 任何帮助表示赞赏。 这是我的子类customMapAnnotation.h: @interface customMapAnnotation : MKPointAnnotation @property (strong, nonatomic) NSString *restaurantID; @property (strong, nonatomic) UIImage *restaurantIcon; @end 这是我的customMapAnnotation创build的地方。 我正在使用Parse.com,所以这里有一个声明将PFFile转换为UIImage。 如果我检查日志,确认foodPoint.restaurantIcon在运行时有一个值。 customMapAnnotation *foodPoint = [[customMapAnnotation alloc] init]; foodPoint.coordinate = spot; foodPoint.restaurantID = [object objectId]; foodPoint.title = [object objectForKey:@"restaurantName"]; foodPoint.subtitle = [object objectForKey:@"cuisineType"]; leftIcon = [object objectForKey:@"restaurantImage"]; [leftIcon getDataInBackgroundWithBlock:^(NSData *data, […]

MKAnnotationView子视图

目前,我在实现具有多个自定义UIImageViews的自定义MKAnnotationView项目中遇到问题。 所以这些自定义的UIImageView有一个清晰的button,不必添加手势识别器。 正如你所看到的,实际上点击MKAnnotationView子视图并且发生一些动作是有益的。 我为MKAnnotationView实现了一个协议,其中MKAnnotationView中的每个图像子视图对MKMapView的所有者控制器进行callback…下面是代码… PHProfileImageView *image = [[PHProfileImageView alloc] initWithFrame:CGRectMake(newX – radius / 5.0f, newY – radius / 5.0f, width, height)]; [image setFile:[object objectForKey:kPHEventPictureKey]]; [image.layer setCornerRadius:image.frame.size.height/2]; [image.layer setBorderColor:[[UIColor whiteColor] CGColor]]; [image.layer setBorderWidth:2.0f]; [image.layer setMasksToBounds:YES]; [image.profileButton setTag:i]; [image.profileButton addTarget:self action:@selector(didTapEvent:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:image]; – (void)didTapEvent:(UIButton *)button { NSLog(@"%@", [self.pins objectAtIndex:button.tag]); if (self.delegate && [self.delegate respondsToSelector:@selector(didTapEvent:)]) { […]