【发布时间】:2016-07-02 05:26:43
【问题描述】:
如何获取Mapkit中的Annotation索引?
到目前为止我尝试的是......
像这样在ViewDidLoad...
[self.mapView addAnnotations:[self createAnnotations]];
在这样的 CreateAnnotations 中......
- (NSMutableArray *)createAnnotations
{
NSMutableArray *annotations = [[NSMutableArray alloc] init];
//Read locations details from plist
NSString * path = [[NSBundle mainBundle] pathForResource:@"locations" ofType:@"plist"];
NSArray * locations = [NSArray arrayWithContentsOfFile:path];
NSDictionary * imageDic;
customTickLocations = [NSMutableArray new];
for (NSDictionary *row in locations) {
NSNumber *latitude = [row objectForKey:@"latitude"];
NSNumber *longitude = [row objectForKey:@"longitude"];
NSString *title = [row objectForKey:@"title"];
NSString * image=[row objectForKey:@"image"];
imageDic =[row objectForKey:image];
[customTickLocations addObject:[row objectForKey:@"image"]];
//Create coordinates from the latitude and longitude values
CLLocationCoordinate2D coord;
coord.latitude = latitude.doubleValue;
coord.longitude = longitude.doubleValue;
MapViewAnnotation * annotation =[[MapViewAnnotation alloc] initWithTitle:image initWithSubTitle:title AndCoordinate:coord];
[annotations addObject:annotation];
}
NSLog(@"%@",customTickLocations);
return annotations;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MapViewAnnotation * annos = view.annotation;
NSInteger indexOfTheObject = [mapView.annotations indexOfObject: annos];
NSString * image =[customTickLocations objectAtIndex:indexOfTheObject];
NSLog(@"------ %ld ------",(long)indexOfTheObject);
}
我正在获取索引,问题是相同引脚的索引值正在变化
请帮帮我
【问题讨论】:
-
试试这个:
NSUInteger indexOfTheObject = [mapView.annotations indexOfObject: view.annotation]; -
@BhavinRamani 谢谢。但问题是一样的
-
但是它还包括用户当前位置?
标签: ios objective-c annotations mapkit