4
votes

I have a view that I am using as an overlay on a MKMapView (it uses OpenGL to draw). For the drawing to be performed correctly, the frame of the glView needs to be exactly the same as the frame of the mapView. I also cannot have the view just be on top of the map, because I want other annotations and overlays to be on top of it.

The way I have tried to do it is to create an MKOverlayView that's boundingMapRect = MKMapRectWorld. I then add the glView as a subview to the overlayView and manually set the glView.frame = mapView.frame. The problem is that the frame of the glView is using a different coordinate system than the mapView is.

The mapView's frame is in the coordinates that you would expect for a standard view (something like 0,0,320,250). The glView's frame seems to be using MKMapPoints as its coordinate base.

So my idea was to do something like this in my MKOverlayView subclass...

glView.frame = [self rectForMapRect:[mapView visibleMapRect]];

This gives me a rect in the correct coordinates (something like 61612032.000000, 105586688.000000, 5275648.000000, 5685248.000000), but it is not perfectly alligned with the map. The y-direction is off and the zoom is sometimes wrong as well.

So my question would be this.

  1. Is there a way to just set the frame of MKOverlayView (or one of its subviews) using normal screen coordinates?
  2. Or is there another way that I could achieve the same thing that I am just missing?
1

1 Answers

3
votes

You can convert cgpoint into mkmappoint by using the mkoverlay method - (MKMapPoint)mapPointForPoint:(CGPoint)point

I hope it helps you

SOURCE: http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html#//apple_ref/occ/instm/MKOverlayView/mapPointForPoint: