Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting position of the annotation relative to screen

I'd like to acquire the position (not map coordinates) of the annotation relative to the screen.

For example, for an annotation on the map, I'd like to know how far that particular pin is from the top left corner (0,0).

I've looked at the documentations, and it does not provide information on its absolute or relative location.

I'll look further into the quartz framework before possibly sub-classing and overriding the rendering methods as a last resort.

Any ideas?

like image 870
Brian Liang Avatar asked Jan 19 '10 15:01

Brian Liang


1 Answers

Given an MKAnnotation, you can get the MKAnnocationView using [MKMapView viewForAnnoation]. You can use that to the get the center of the view in window coordinates:

CGPoint windowPoint = [annView convertPoint:[annView center] toView:window]

The main UIWindow is generally available through your AppDelegate.

like image 99
Rob Napier Avatar answered Oct 13 '22 08:10

Rob Napier