How to display several MKPinAnnotation with same Latitude / Longitude?

My iPad App is retrieving geographical objects from a database. In this database some objects have the same longitude / Latitude. As a consequence in the MkMapView I'm adding several MKPinAnnotation with the same Lat/Long. Unfortunately only one is displayed, I suppose it the last one I have added.

How can I have only one MKPinAnnotation object (for a given coordinate) and when user clicks on it I will display MKPinAnnotation for each objects sharing the same coordinates? Something similar to what is done by Google Maps / Google Earth, you click on the main Pin and then several Pin are display.

Any help will be appreciated.

S├ębastien.

Answers


Do you think that multiple pins are being displayed on top of each other when they are at the exact same coordinate? Or is it possible that Apple culls the additional pins at the same coordinate?

Either way, I would suggest changing the coordinates so that they can be seen to be clearly separate. What you could do is find all the pins that are extremely close to each other by using the distanceFromLocation: method of CLLocation. Once you have found that there are some pins that are a tiny distance (say < 0.01) from each other, then you could amend their coordinates before adding them to the map. You could make them form a small circle around the actual exact coordinate, with the angle around the circle determined by how many in that cluster (e.g. for 4 pins, place them at 0, 90, 180, 270 degrees). Or you could change the latitude only, by a very small amount, so that the pins appear to stack up on each other in a vertical line.

You could also do this separation when the user taps on an individual pin. i.e. for that pin, check if there are any other pins that are very close. If there are, remove this pin (or maybe remove all those pins), calculate new positions for all the pins in a circle or vertical line, then re-add the pins to the map (and open any callout view if required).

Once the pins have been separated in this manner, it will be easy for the user to tap on the individual pins.

I'm not exactly sure how Google Maps/Google Earth deal with this issue - could you describe it or provide a screenshot? Or mention some search terms that will cause it to happen. But hopefully the ideas above will give you something to try.


You could simply combine them to one annotationView and when the user touches it make some fancy animation inside that annotationView to present the content.

I have built a useful control for clustering nearby pins (also for pins with the same coordinate) on MKMapView since i had the same problems a couple of times. It is called OCMapView. It can combine the annotation for you, but you will have to implement the animation stuff on user touch on your own.


Need Your Help

UDP socket problem

c++ sockets udp winsock client-server

I'm writing a multiplayer game (obviously using UDP sockets. note: using winsock 2.2). The server code reads something like this:

Fastest key-value pair database?

database performance key-value-store

I am looking for fastest free key-value pair database available. Database doesn't have to be server-based, it can be linked into the application. I am aware of Tokyo Cabinet. Any other suggestions?