如何在同一纬度/经度添加多个引脚 [英] how to add multiple pin at the same lat/long
本文介绍了如何在同一纬度/经度添加多个引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在同一位置添加多个图钉.
I am trying to add multiple pin at the same location.
for (int i = 0; i < [arrListing count]; i++) {
List *obj = [arrListing objectAtIndex:i];
NSLog(@"Title %@",obj.Title);
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = [obj.lat floatValue];
annotationCoord.longitude = [obj.log floatValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = obj.Title;
[mapView addAnnotation:annotationPoint];
}
以上代码表示添加多个注解但是很多针都在同一个位置
the above code represent adding mulitiple annotation but many pin are at the same location
所以我只能看到.那个时候的最后一个和倒数第二个.下面是 viewForAnnotation 的代码
So I can see only. last and the second last at that point. below is the code for the viewForAnnotation
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annView"];
if (!annView) {
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annView"];
annView.pinColor = MKPinAnnotationColorRed;
annView.animatesDrop = YES;
annView.canShowCallout = YES;
NSLog(@"iRow :%d",iRow);
annView.tag = iRow++;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = rightButton;
NSLog(@"if condition");
}
else
{
annView.annotation = annotation;
NSLog(@"else condition");
}
return annView;
}
推荐答案
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation != map.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[map.userLocation setTitle:@"I am here"];
}
return pinView;
}
这篇关于如何在同一纬度/经度添加多个引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文