How to handle multiple annotations with the same lengths and lats in MapView

I write contacts for contacts, and some have the same longitude and latitude. When the pins are dropped onto the map, they appear, but when I touch once, which has more than two pins, I only see the first and last.

So what is the best way to handle multiple pins on the same length and lat?

Ideally, I thought I could tell you how much is in that place, and then I hoped that the user could keep touching the pin and loop through the annotations. I'm not sure how to do this, or if there is a better solution.

Thanks for any help or understanding of the problem.

+3


source to share


2 answers


I would make one annotation representing the NSDictionary of all contacts / objects at that latitude and longitude. They represent several armor and a long one with a different colored pin.

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    static NSString *identifier = @"AnnotationIdentifier";

    if ([annotation isKindOfClass:[NSDictionary class]]) {
//Code here to show red pin vs. blue pin
}
}

      

You will need a custom init method to subclass MKPinAnnotationView, for example:



-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinateC:(NSDictionary *)dictionaryParam;

      

Finally, to run a method when this pin is touched, something like this:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
     if ([view.annotation class] == [NSDictionary class]) {
        NSLog(@"multiple");

// more code here to run a view for multiple contacts

    }
    else
    {
...
}
}

      

0


source


Here's the idea:

k-means



Run the K-Means Algorithm (see fooobar.com/questions/1479207 / ... ) over existing annotations and discard the cluster annotation when the contact density exceeds an arbitrary number. If the user touches the output, you can add annotations and animate them coming from the pin. I suggest you disable interactions during animation because the logic gets messy.

0


source







All Articles