Skip to content

Instantly share code, notes, and snippets.

@Arpit723
Created December 23, 2021 06:55
Show Gist options
  • Select an option

  • Save Arpit723/519f40a604773ac761cbb45d1b316b97 to your computer and use it in GitHub Desktop.

Select an option

Save Arpit723/519f40a604773ac761cbb45d1b316b97 to your computer and use it in GitHub Desktop.

Revisions

  1. Arpit723 created this gist Dec 23, 2021.
    36 changes: 36 additions & 0 deletions FriendMapListVC.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    -(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];
    }

    }];

    }