Ios 如何使用现有注释添加新注释?
在我的申请中,我被发布了从特定位置录制的视频。我可以从另一个服务响应获取已发布位置详细信息的列表。因此,最初我获得了发布的位置详细信息,并将其显示在MapView上。在MapView中,管脚以集群效果显示,因此我使用了 下面我已经在地图上加载了注释Ios 如何使用现有注释添加新注释?,ios,objective-c,annotations,mkmapview,markerclusterer,Ios,Objective C,Annotations,Mkmapview,Markerclusterer,在我的申请中,我被发布了从特定位置录制的视频。我可以从另一个服务响应获取已发布位置详细信息的列表。因此,最初我获得了发布的位置详细信息,并将其显示在MapView上。在MapView中,管脚以集群效果显示,因此我使用了 下面我已经在地图上加载了注释 - (void)loadLocations:(NSArray *)arrayValues { _annotationArray = arrayValues; [self.clusteringController setAnnota
- (void)loadLocations:(NSArray *)arrayValues
{
_annotationArray = arrayValues;
[self.clusteringController setAnnotations:[self reSetannotations]];
[self.mapView setZoomEnabled:YES];
[self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate];
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow];
KPGridClusteringAlgorithm *algorithm = [KPGridClusteringAlgorithm new];
algorithm.annotationSize = CGSizeMake(25, 50);
algorithm.clusteringStrategy = KPGridClusteringAlgorithmStrategyTwoPhase;
self.clusteringController = [[KPClusteringController alloc] initWithMapView:self.mapView
clusteringAlgorithm:algorithm];
self.clusteringController.delegate = self;
self.clusteringController.animationOptions = UIViewAnimationOptionCurveEaseOut;
[self.clusteringController setAnnotations:[self annotations]];
NSString * lastobjlat;
double miles;
CLLocation * location = [COMMON currentLocation];
lastobjlat = [NSString stringWithFormat:@"%f",location.coordinate.latitude];
miles = 1.;
double scalingFactor = ABS( (cos(2 * M_PI * [lastobjlat floatValue] / 360.0) ));
MKCoordinateSpan span;
span.latitudeDelta = miles/69.0;
span.longitudeDelta = miles/(scalingFactor * 69.0);
MKCoordinateRegion region;
region.span = span;
region.center = location.coordinate;
[self.mapView setRegion:region animated:YES];
self.mapView.showsUserLocation = YES;
//Call in the below selectAnnotationAction method when I came to this, after I published new one on existed or new locations
if (COMMON.isRecentPublication == YES) {
COMMON.isRecentPublication = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self selectAnnotationAction];
});
}
}
//重置批注的步骤
- (NSArray *)reSetannotations
{
NSMutableArray *annotations = [NSMutableArray array];
return annotations;
}
//在这里,我管理了自定义标记类MapAnnotation上的位置详细信息
- (NSArray *)annotations {
CLLocationCoordinate2D locationPort;
NSMutableArray *annotations = [NSMutableArray array];
NSString *latitude, *longitude;
if ([_annotationArray count] > 0) {
for (int i = 0; i <[_annotationArray count]; i++){
latitude = [NSString stringWithFormat:@"%@",[[_annotationArray objectAtIndex:i] valueForKey:@"latitude"]];
latitude = [latitude stringByReplacingOccurrencesOfString:@"\n" withString:@""];
latitude = [latitude stringByReplacingOccurrencesOfString:@"\t" withString:@""];
longitude = [NSString stringWithFormat:@"%@",[[_annotationArray objectAtIndex:i] valueForKey:@"longitude"]];
longitude = [longitude stringByReplacingOccurrencesOfString:@"\n" withString:@""];
longitude = [longitude stringByReplacingOccurrencesOfString:@"\t" withString:@""];
latitude = [NSString replaceEmptyStringInsteadOfNull:latitude];
longitude = [NSString replaceEmptyStringInsteadOfNull:longitude];
int publicationRatio = [[[_annotationArray objectAtIndex:i] valueForKey:@"publicationRatio"] intValue];
int publicationCount = [[[_annotationArray objectAtIndex:i] valueForKey:@"publicationsCount"] intValue];
int teazLocationId = [[[_annotationArray objectAtIndex:i] valueForKey:@"objectId"] intValue];
BOOL isUpgrade = [[[_annotationArray objectAtIndex:i] valueForKey:@"isUpgraded"] boolValue];
locationPort = CLLocationCoordinate2DMake([latitude doubleValue] ,
[longitude doubleValue]);
//TODO : This is my custom annotation method
MapAnnotation *a1 = [[MapAnnotation alloc] initWithCoordinate:locationPort
tag:i
publicationRatio:publicationRatio
publicationCount:publicationCount
teazLocationId:teazLocationId isUpgraded:isUpgrade];
a1.itemindex = i + 1;
a1.publicationRatio = publicationRatio;
a1.publicationCount = publicationCount;
a1.teazLocationId = teazLocationId;
a1.isUpgraded = isUpgrade;
a1.coordinate = CLLocationCoordinate2DMake([latitude doubleValue] ,
[longitude doubleValue] );
[annotations addObject:a1];
if (COMMON.isRecentPublication == YES) {
if ([COMMON.recentPublicationLocationID isEqual: @(publishedLocationId)]) {
_recentAnnotationView = [[MKPinAnnotationView alloc] initWithAnnotation:a1 reuseIdentifier:@"cluster"];
}
}
}
}
return annotations;
}
//选择注释动作
- (void)selectAnnotationAction {
COMMON.isRecentPublication = NO;
COMMON.recentPublicationLocationID = nil;
[self mapView:self.mapView didSelectAnnotationView:_recentAnnotationView];
}
如果我直接将recentPublishedLocation详细信息传递给didSelectAnnotationView委托,我只能在活动pin中显示,而不是活动pin
然后我用断点调试,为什么我只能在活动管脚中看到
因为在这种情况下,调用了didselect委托,我可以看到活动pin图像。但这只需要几秒钟
因为其他pin注释快速调用了viewForAnnotation委托,所以选定的pin注释将进入未选定状态
这才是真正的问题。如何使用集群解决这一问题
因为当我在地图上正确地显示发布的位置细节时,它应该具有集群效果。是的,我将放大以查看具有群集效果的管脚。最后,我得到了解决方案,并使用而不是实现了我的要求 这个工具真的很有帮助,可以帮助我实现附加注释,并根据我的需求定制每件事情 所以这对我更有帮助。当然,你们所有人 该工具支持苹果和谷歌地图,包括Objective c和Swift 我希望这一点对其他开发者也更有帮助
谢谢:)你真的希望一个陌生人能读到所有这些文字吗?@EI-Tomato我需要建议,所以我只是解释了我做的。这就是为什么我用文字来解释。所以我不能忽视它。
- (void)selectAnnotationAction {
COMMON.isRecentPublication = NO;
COMMON.recentPublicationLocationID = nil;
[self mapView:self.mapView didSelectAnnotationView:_recentAnnotationView];
}