Search code examples
iosdictionarypositionmkmapviewrect

iOS. How to get an information about current map rect after each action with this map?


For example, I want to display the current x, y, width and height of the map rect, but I don't know what events should I handle. At least I want to catch the double click, zoom and dragging.


Solution

  • Check the documentation for the MKMapViewDelegate protocol. You have these available methods: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html

    – mapView:regionWillChangeAnimated:
    – mapView:regionDidChangeAnimated:
    – mapViewWillStartLoadingMap:
    – mapViewDidFinishLoadingMap:
    – mapViewDidFailLoadingMap:withError:
    – mapViewWillStartLocatingUser:
    – mapViewDidStopLocatingUser:
    – mapView:didUpdateUserLocation:
    – mapView:didFailToLocateUserWithError:
    – mapView:viewForAnnotation:
    – mapView:didAddAnnotationViews:
    – mapView:annotationView:calloutAccessoryControlTapped:
    – mapView:annotationView:didChangeDragState:fromOldState:
    – mapView:didSelectAnnotationView:
    – mapView:didDeselectAnnotationView:
    – mapView:viewForOverlay:
    – mapView:didAddOverlayViews:
    

    Also, MKMapView inherits from UIScrollView, so by setting yourself as the delegate, you can also adopt the UIScrollViewDelegate protocol, and use these methods: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html