// // MKMapView.h // MapKit // // Copyright (c) 2009-2014, Apple Inc. All rights reserved. // #import #if MK_SUPPORTS_VIEW_CLASSES #import #import #import #import #import #if TARGET_OS_IPHONE #import #endif #if TARGET_OS_IOS #import #endif @class MKUserLocation; @class MKMapCamera; @class MKMapCameraZoomRange; @class MKMapCameraBoundary; @class MKClusterAnnotation; @class MKPointOfInterestFilter; @class MKMapConfiguration; @protocol MKMapViewDelegate; NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSInteger, MKUserTrackingMode) { MKUserTrackingModeNone = 0, // the user's location is not followed MKUserTrackingModeFollow, // the map follows the user's location MKUserTrackingModeFollowWithHeading API_UNAVAILABLE(macos) API_UNAVAILABLE(tvos), // the map follows the user's location and heading } API_AVAILABLE(ios(5.0), tvos(9.2), macos(11.0)) API_UNAVAILABLE(watchos); #if TARGET_OS_IOS typedef NS_OPTIONS(NSInteger, MKMapFeatureOptions) { MKMapFeatureOptionPointsOfInterest = 1 << MKMapFeatureTypePointOfInterest, MKMapFeatureOptionTerritories = 1 << MKMapFeatureTypeTerritory, MKMapFeatureOptionPhysicalFeatures = 1 << MKMapFeatureTypePhysicalFeature, } API_AVAILABLE(ios(16.0)) API_UNAVAILABLE(macos, tvos, watchos); #endif MK_EXTERN NSString * const MKMapViewDefaultAnnotationViewReuseIdentifier NS_AVAILABLE(10_13, 11_0) __TVOS_AVAILABLE(11_0); MK_EXTERN NSString * const MKMapViewDefaultClusterAnnotationViewReuseIdentifier NS_AVAILABLE(10_13, 11_0) __TVOS_AVAILABLE(11_0); #if TARGET_OS_IPHONE NS_CLASS_AVAILABLE(NA, 3_0) __TVOS_AVAILABLE(9_2) API_UNAVAILABLE(watchos) @interface MKMapView : UIView #else NS_CLASS_AVAILABLE(10_9, NA) @interface MKMapView : NSView #endif @property (nonatomic, weak, nullable) IBOutlet id delegate; // Changing the map type or region can cause the map to start loading map content. // The loading delegate methods will be called as map content is loaded. @property (nonatomic) MKMapType mapType API_DEPRECATED_WITH_REPLACEMENT("Use respective MKMapConfiguration", macos(10.9, API_TO_BE_DEPRECATED), ios(3.0, API_TO_BE_DEPRECATED), tvos(9.2, API_TO_BE_DEPRECATED)); @property (nonatomic, copy) MKMapConfiguration *preferredConfiguration API_AVAILABLE(ios(16.0), macos(13.0), tvos(16.0)) API_UNAVAILABLE(watchos); #if TARGET_OS_IOS @property (nonatomic) MKMapFeatureOptions selectableMapFeatures API_AVAILABLE(ios(16.0)) API_UNAVAILABLE(macos, tvos, watchos); #endif // Region is the coordinate and span of the map. // Region may be modified to fit the aspect ratio of the view using regionThatFits:. @property (nonatomic) MKCoordinateRegion region; - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated; // centerCoordinate allows the coordinate of the region to be changed without changing the zoom level. @property (nonatomic) CLLocationCoordinate2D centerCoordinate; - (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated; // Returns a region of the aspect ratio of the map view that contains the given region, with the same center point. - (MKCoordinateRegion)regionThatFits:(MKCoordinateRegion)region; // Access the visible region of the map in projected coordinates. @property (nonatomic) MKMapRect visibleMapRect; - (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate; // Returns an MKMapRect modified to fit the aspect ratio of the map. - (MKMapRect)mapRectThatFits:(MKMapRect)mapRect; // Edge padding is the minumum padding on each side around the specified MKMapRect. #if TARGET_OS_IPHONE - (void)setVisibleMapRect:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animate; - (MKMapRect)mapRectThatFits:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets; #else - (void)setVisibleMapRect:(MKMapRect)mapRect edgePadding:(NSEdgeInsets)insets animated:(BOOL)animate; - (MKMapRect)mapRectThatFits:(MKMapRect)mapRect edgePadding:(NSEdgeInsets)insets; #endif @property (nonatomic, copy) MKMapCamera *camera NS_AVAILABLE(10_9, 7_0); - (void)setCamera:(MKMapCamera *)camera animated:(BOOL)animated NS_AVAILABLE(10_9, 7_0); @property (nonatomic, copy, null_resettable) MKMapCameraZoomRange *cameraZoomRange API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0)) API_UNAVAILABLE(watchos); - (void)setCameraZoomRange:(nullable MKMapCameraZoomRange *)cameraZoomRange animated:(BOOL)animated API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0)) API_UNAVAILABLE(watchos); @property (nonatomic, copy, nullable) MKMapCameraBoundary *cameraBoundary API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0)) API_UNAVAILABLE(watchos); - (void)setCameraBoundary:(nullable MKMapCameraBoundary *)cameraBoundary animated:(BOOL)animated API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0)) API_UNAVAILABLE(watchos); #if TARGET_OS_IPHONE - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view; - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view; - (CGRect)convertRegion:(MKCoordinateRegion)region toRectToView:(nullable UIView *)view; - (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(nullable UIView *)view; #else - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable NSView *)view; - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable NSView *)view; - (CGRect)convertRegion:(MKCoordinateRegion)region toRectToView:(nullable NSView *)view; - (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(nullable NSView *)view; #endif // Control the types of user interaction available // Zoom and scroll are enabled by default. @property (nonatomic, getter=isZoomEnabled) BOOL zoomEnabled; @property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled; // Rotate and pitch are enabled by default on Mac OS X and on iOS 7.0 and later. @property (nonatomic, getter=isRotateEnabled) BOOL rotateEnabled NS_AVAILABLE(10_9, 7_0) API_UNAVAILABLE(tvos); @property (nonatomic, getter=isPitchEnabled) BOOL pitchEnabled NS_AVAILABLE(10_9, 7_0) API_UNAVAILABLE(tvos); @property (nonatomic) BOOL showsPitchControl API_AVAILABLE(macos(11.0), macCatalyst(14.0)) API_UNAVAILABLE(ios, watchos, tvos); @property (nonatomic) BOOL showsZoomControls API_AVAILABLE(macos(10.9), macCatalyst(13.0)) API_UNAVAILABLE(ios, watchos, tvos); @property (nonatomic) BOOL showsCompass NS_AVAILABLE(10_9, 9_0) API_UNAVAILABLE(tvos); @property (nonatomic) BOOL showsScale NS_AVAILABLE(10_10, 9_0); @property (nonatomic, copy, nullable) MKPointOfInterestFilter *pointOfInterestFilter API_DEPRECATED_WITH_REPLACEMENT("Use pointOfInterestFilter on respective MKMapConfiguration", macos(10.15, API_TO_BE_DEPRECATED), ios(13.0, API_TO_BE_DEPRECATED), tvos(13.0, API_TO_BE_DEPRECATED)) API_UNAVAILABLE(watchos); @property (nonatomic) BOOL showsPointsOfInterest API_DEPRECATED("Use pointOfInterestFilter", macos(10.9, 10.15), ios(7.0, 13.0), tvos(9.0, 13.0)) API_UNAVAILABLE(watchos); // Affects MKMapTypeStandard and MKMapTypeHybrid @property (nonatomic) BOOL showsBuildings API_DEPRECATED("None", macos(10.9, API_TO_BE_DEPRECATED), ios(7.0, API_TO_BE_DEPRECATED), tvos(9.0, API_TO_BE_DEPRECATED)); // Affects MKMapTypeStandard @property (nonatomic) BOOL showsTraffic API_DEPRECATED_WITH_REPLACEMENT("Use showsTraffic on respective MKMapConfiguration", macos(10.11, API_TO_BE_DEPRECATED), ios(9.0, API_TO_BE_DEPRECATED), tvos(9.0, API_TO_BE_DEPRECATED)); // Affects MKMapTypeStandard and MKMapTypeHybrid // Set to YES to add the user location annotation to the map and start updating its location @property (nonatomic) BOOL showsUserLocation; // The annotation representing the user's location @property (nonatomic, readonly) MKUserLocation *userLocation; @property (nonatomic) MKUserTrackingMode userTrackingMode API_AVAILABLE(ios(5.0), tvos(9.2), macos(11.0)) API_UNAVAILABLE(watchos); - (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated API_AVAILABLE(ios(5.0), tvos(9.2), macos(11.0)) API_UNAVAILABLE(watchos); // Returns YES if the user's location is displayed within the currently visible map region. @property (nonatomic, readonly, getter=isUserLocationVisible) BOOL userLocationVisible; // Annotations are models used to annotate coordinates on the map. // Implement mapView:viewForAnnotation: on MKMapViewDelegate to return the annotation view for each annotation. - (void)addAnnotation:(id )annotation; - (void)addAnnotations:(NSArray> *)annotations; - (void)removeAnnotation:(id )annotation; - (void)removeAnnotations:(NSArray> *)annotations; @property (nonatomic, readonly) NSArray> *annotations; - (NSSet> *)annotationsInMapRect:(MKMapRect)mapRect NS_AVAILABLE(10_9, 4_2); // Currently displayed view for an annotation; returns nil if the view for the annotation isn't being displayed. - (nullable MKAnnotationView *)viewForAnnotation:(id )annotation; // Used by the delegate to acquire a reusable annotation view, or create a new view for registered class, in lieu of allocating a new one. - (nullable MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier; // Used by the delegate to acquire a reusable annotation view, or create a new view for registered class, in lieu of allocating a new one. Throws an exception if view could not be aquired. - (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier forAnnotation:(id)annotation NS_AVAILABLE(10_13, 11_0) __TVOS_AVAILABLE(11_0); // Register a MKAnnotationView subclass to be instantiated when dequeueReusableAnnotationViewWithIdentifier: does not have a view to reuse. - (void)registerClass:(nullable Class)viewClass forAnnotationViewWithReuseIdentifier:(NSString *)identifier NS_AVAILABLE(10_13, 11_0) __TVOS_AVAILABLE(11_0); // Select or deselect a given annotation. Asks the delegate for the corresponding annotation view if necessary. - (void)selectAnnotation:(id )annotation animated:(BOOL)animated; - (void)deselectAnnotation:(nullable id )annotation animated:(BOOL)animated; @property (nonatomic, copy) NSArray> *selectedAnnotations; // annotationVisibleRect is the visible rect where the annotations views are currently displayed. // The delegate can use annotationVisibleRect when animating the adding of the annotations views in mapView:didAddAnnotationViews: @property (nonatomic, readonly) CGRect annotationVisibleRect; // Position the map such that the provided array of annotations are all visible to the fullest extent possible. - (void)showAnnotations:(NSArray> *)annotations animated:(BOOL)animated NS_AVAILABLE(10_9, 7_0); @end typedef NS_ENUM(NSInteger, MKOverlayLevel) { MKOverlayLevelAboveRoads = 0, // note that labels include shields and point of interest icons. MKOverlayLevelAboveLabels } NS_ENUM_AVAILABLE(10_9, 7_0) __TVOS_AVAILABLE(9_2) API_UNAVAILABLE(watchos); @interface MKMapView (OverlaysAPI) // Overlays are models used to represent areas to be drawn on top of the map. // This is in contrast to annotations, which represent points on the map. // Implement -mapView:rendererForOverlay: on MKMapViewDelegate to return the renderer for each overlay. - (void)addOverlay:(id )overlay level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0); - (void)addOverlays:(NSArray> *)overlays level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0); - (void)removeOverlay:(id )overlay NS_AVAILABLE(10_9, 4_0); - (void)removeOverlays:(NSArray> *)overlays NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id )overlay atIndex:(NSUInteger)index level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0); - (void)insertOverlay:(id )overlay aboveOverlay:(id )sibling NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id )overlay belowOverlay:(id )sibling NS_AVAILABLE(10_9, 4_0); - (void)exchangeOverlay:(id )overlay1 withOverlay:(id )overlay2 NS_AVAILABLE(10_9, 7_0); @property (nonatomic, readonly) NSArray> *overlays NS_AVAILABLE(10_9, 4_0); - (NSArray> *)overlaysInLevel:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0); // Current renderer for overlay; returns nil if the overlay is not shown. - (nullable MKOverlayRenderer *)rendererForOverlay:(id )overlay NS_AVAILABLE(10_9, 7_0); #if TARGET_OS_IPHONE // Currently displayed view for overlay; returns nil if the view has not been created yet. // Prefer using MKOverlayRenderer and -rendererForOverlay. - (MKOverlayView *)viewForOverlay:(id )overlay API_DEPRECATED_WITH_REPLACEMENT("-rendererForOverlay:", ios(4.0, 13.0)) API_UNAVAILABLE(macos, tvos, watchos); #endif // These methods operate implicitly on overlays in MKOverlayLevelAboveRoads and may be deprecated in a future release in favor of the methods that specify the level. - (void)addOverlay:(id )overlay NS_AVAILABLE(10_9, 4_0); - (void)addOverlays:(NSArray> *)overlays NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id )overlay atIndex:(NSUInteger)index NS_AVAILABLE(10_9, 4_0); - (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2 NS_AVAILABLE(10_9, 4_0); @end API_UNAVAILABLE(watchos) @protocol MKMapViewDelegate @optional - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated; - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated; - (void)mapViewDidChangeVisibleRegion:(MKMapView *)mapView API_AVAILABLE(ios(11), tvos(11), macos(10.13)); - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error; - (void)mapViewWillStartRenderingMap:(MKMapView *)mapView NS_AVAILABLE(10_9, 7_0); - (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered NS_AVAILABLE(10_9, 7_0); // mapView:viewForAnnotation: provides the view for each annotation. // This method may be called for all or some of the added annotations. // For MapKit provided annotations (eg. MKUserLocation) return nil to use the MapKit provided annotation view. - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation; // mapView:didAddAnnotationViews: is called after the annotation views have been added and positioned in the map. // The delegate can implement this method to animate the adding of the annotations views. // Use the current positions of the annotation views as the destinations of the animation. - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views; #if TARGET_OS_IPHONE // mapView:annotationView:calloutAccessoryControlTapped: is called when the user taps on left & right callout accessory UIControls. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control API_UNAVAILABLE(tvos); #endif - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView didSelectAnnotation:(id)annotation API_AVAILABLE(ios(16.0)) API_UNAVAILABLE(macos, tvos, watchos); - (void)mapView:(MKMapView *)mapView didDeselectAnnotation:(id)annotation API_AVAILABLE(ios(16.0)) API_UNAVAILABLE(macos, tvos, watchos); - (void)mapViewWillStartLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0); - (void)mapViewDidStopLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error NS_AVAILABLE(10_9, 4_0); - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState NS_AVAILABLE(10_9, 4_0) API_UNAVAILABLE(tvos); - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated API_AVAILABLE(ios(5.0), tvos(9.2), macos(11.0)) API_UNAVAILABLE(watchos); - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id )overlay NS_AVAILABLE(10_9, 7_0); - (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray *)renderers NS_AVAILABLE(10_9, 7_0); #if TARGET_OS_IPHONE // Prefer -mapView:rendererForOverlay: - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay API_DEPRECATED_WITH_REPLACEMENT("-mapView:rendererForOverlay:", ios(4.0, 13.0)) API_UNAVAILABLE(macos, tvos, watchos); // Called after the provided overlay views have been added and positioned in the map. // Prefer -mapView:didAddOverlayRenderers: - (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews API_DEPRECATED_WITH_REPLACEMENT("-mapView:didAddOverlayRenderers:", ios(4.0, 13.0)) API_UNAVAILABLE(macos, tvos, watchos); #endif // Return nil for default MKClusterAnnotation, it is illegal to return a cluster annotation not containing the identical array of member annotations given. - (MKClusterAnnotation *)mapView:(MKMapView *)mapView clusterAnnotationForMemberAnnotations:(NSArray>*)memberAnnotations NS_AVAILABLE(10_13, 11_0) __TVOS_AVAILABLE(11_0) API_UNAVAILABLE(watchos); @end NS_ASSUME_NONNULL_END #endif // MK_SUPPORTS_VIEW_CLASSES