Brian Liang
Brian Liang

Reputation: 7774

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?

Upvotes: 6

Views: 1368

Answers (1)

Rob Napier
Rob Napier

Reputation: 299355

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.

Upvotes: 3

Related Questions