Created
December 23, 2021 06:55
-
-
Save Arpit723/519f40a604773ac761cbb45d1b316b97 to your computer and use it in GitHub Desktop.
People Map Loading, Single Cluster loads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)findAndMoveToCenterOfTheCity:(POIItem1*)poiItem { | |
NSLog(@"%s",__PRETTY_FUNCTION__); | |
[self addClusterToRenderingArray:poiItem]; | |
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; | |
CLLocation *location = [[CLLocation alloc] initWithLatitude:poiItem.position.latitude longitude:poiItem.position.longitude]; | |
[geocoder reverseGeocodeLocation:location | |
completionHandler:^(NSArray *placemarks, NSError *error) | |
{ | |
if (error || placemarks.count == 0){ | |
NSLog(@"Geocode failed with error: %@", error); | |
[self removeClusterFromRenderingArray:poiItem]; | |
return; | |
} | |
//Getting city name to center of the city coordinates | |
[self removeClusterFromRenderingArray:poiItem]; | |
CLPlacemark *placemark = [placemarks objectAtIndex:0]; | |
CLLocation *oldLocation = [[CLLocation alloc] initWithLatitude:poiItem.position.latitude longitude:poiItem.position.longitude]; | |
CLLocation *newCenterLocation = [[CLLocation alloc] initWithLatitude:placemark.region.center.latitude longitude:placemark.region.center.longitude]; | |
double distance = [oldLocation distanceFromLocation:newCenterLocation]; | |
if (distance > 200) { | |
[self removeItemFromCluster:poiItem]; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
id<GMUClusterItem> item = [[POIItem1 alloc] initWithPosition:placemark.region.center name:poiItem.name markerData:poiItem.markerData]; | |
[self->_clusterManager addItem:item]; | |
[self->_clusterManager cluster]; | |
NSLog(@"Added cluster to the center of the city"); | |
}); | |
}else{ | |
NSLog(@"Not adding marker.Distance is less than 10 meters."); | |
// id<GMUClusterItem> item = [[POIItem1 alloc] initWithPosition:centerOfTheCity.location.coordinate name:poiItem.name markerData:poiItem.markerData]; | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment