在我的申请中,我被发布了从特定位置录制的视频。我可以从另一个服务响应中获得已发布位置详细信息的列表。最初,我得到了发布的位置详细信息,并将其显示在MapView上。在MapView中,接点显示为
效果,所以我用
kingpin
.
在下面,我已将注释加载到地图上。
- (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;
}
- (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;
}
在初始时间加载具有聚类效果的注释不是问题。但是,当我从相同或不同(也是新的)位置发布某个地图时,我需要重定向地图屏幕(发布部分是另一个屏幕),我需要用
活动pin图像
.
-
我创建了
最近发布位置ID
作为全局变量,并存储发布服务后响应中的recentPublishedLocationID。
-
那么这个返回类型方法
-(NSArray*)注释
(重定向到mapView后,我从另一个Web服务获得了位置详细信息,之后它将调用),
如果存在或不存在,我将与最近发布的版本进行比较。然后,如果存在,我已将自定义注释(包含最近发布的位置详细信息)分配给全局
MKPinAnnotationView实例-\u recentAnnotationView
-
然后我直接打电话给
-(void)加载位置:(NSArray*)阵列值
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];
});
}
//选择注释操作
- (void)selectAnnotationAction {
COMMON.isRecentPublication = NO;
COMMON.recentPublicationLocationID = nil;
[self mapView:self.mapView didSelectAnnotationView:_recentAnnotationView];
}
如果我直接通过
详细信息至
DID选择注释视图
在活动引脚中
而不是
.
在活动引脚中
只有
因为在这种情况下,调用了didselect委托,我可以看到
因为其他管脚注释快速调用了viewForAnnotation委托,所以选定的管脚注释将变为未选定状态
这才是真正的问题。如何使用集群克服这一问题?
因为当我在地图上正确显示发布的位置细节时,它甚至应该具有聚类效果。是的,我将缩小以查看具有簇效果的管脚。