Manually Setting the MKOverlayView (or subview) Frame

I have an idea of ​​what I'm using as an overlay on MKMapView (it uses OpenGL for drawing). For the drawing to run correctly, the glView frame must be exactly the same as the mapView frame. I also cannot have an idea just above the map, because I want other annotations and overlays to be above it.

The way I tried to do this was to create an MKOverlayView that bounds MapRect = MKMapRectWorld. Then I add glView as a subview to overlayView and manually set glView.frame = mapView.frame. The problem is that the glView frame uses a different coordinate system than mapView.

The mapView frame is in the coordinates that you expect for a standard view (approximately 0,0,320,250). The glView frame apparently uses MKMapPoints as its base of coordinates.

So my idea was to do something similar in my subclass of MKOverlayView ...

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

This gives me the right in the correct coordinates (something like 61612032.000000, 105586688.000000, 5275648.000000, 5685248.000000), but it is not completely attached to the map. The y-direction is off, and the zoom is also erroneous.

So my question will be this.

  • Is there a way to set the MKOverlayView frame (or one of its subzones) using normal screen coordinates?
  • Or is there another way I could achieve the same thing that I just missed?
+4
source share
1 answer

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

I hope this helps you

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

+3
source

Source: https://habr.com/ru/post/1382192/


All Articles