Class: MKMapView
Overview
An MKMapView object provides an embeddable map interface, similar to the one provided by the Maps application. You use this class as-is to display map information and to manipulate the map contents from your application. You can center the map on a given coordinate, specify the size of the area you want to display, and annotate the map with custom information.
Instance Attribute Summary (collapse)
-
- annotations
readonly
The complete list of annotations associated with the receiver.
-
- annotationVisibleRect
readonly
The visible rectangle where annotation views are currently being displayed.
-
- centerCoordinate
The map coordinate at the center of the map view.
-
- delegate
The receiver’s delegate.
-
- mapType
The type of data displayed by the map view.
-
- overlays
readonly
The overlay objects currently associated with the map view.
-
- region
The area currently displayed by the map view.
-
- scrollEnabled
A Boolean value that determines whether the user may scroll around the map.
-
- selectedAnnotations
The annotations that are currently selected.
-
- showsUserLocation
A Boolean value indicating whether the map may display the user location.
-
- userLocation
readonly
The annotation object representing the user’s current location.
-
- userLocationVisible
readonly
A Boolean value indicating whether the device’s current location is visible in the map view.
-
- userTrackingMode
The mode used to track the user location.
-
- visibleMapRect
The area currently displayed by the map view.
-
- zoomEnabled
A Boolean value that determines whether the user may use pinch gestures to zoom in and out of the map.
Attributes inherited from UIView
#alpha, #autoresizesSubviews, #autoresizingMask, #backgroundColor, #bounds, #center, #clearsContextBeforeDrawing, #clipsToBounds, #contentMode, #contentScaleFactor, #exclusiveTouch, #frame, #gestureRecognizers, #hidden, #layer, #multipleTouchEnabled, #opaque, #restorationIdentifier, #subviews, #superview, #tag, #transform, #userInteractionEnabled, #window
Attributes inherited from UIResponder
#inputAccessoryView, #inputView, #undoManager
Instance Method Summary (collapse)
-
- addAnnotation:
Adds the specified annotation to the map view.
-
- addAnnotations:
Adds an array of annotation objects to the map view.
-
- addOverlay:
Adds a single overlay object to the map.
-
- addOverlays:
Adds an array of overlay objects to the map.
-
- annotationsInMapRect:
Returns the annotation objects located in the specified map rectangle.
-
- convertCoordinate:toPointToView:
Converts a map coordinate to a point in the specified view.
-
- convertPoint:toCoordinateFromView:
Converts a point in the specified view’s coordinate system to a map coordinate.
-
- convertRect:toRegionFromView:
Converts a rectangle in the specified view’s coordinate system to a map region.
-
- convertRegion:toRectToView:
Converts a map region to a rectangle in the specified view.
-
- dequeueReusableAnnotationViewWithIdentifier:
Returns a reusable annotation view located by its identifier.
-
- deselectAnnotation:animated:
Deselects the specified annotation and hides its callout view.
-
- exchangeOverlayAtIndex:withOverlayAtIndex:
Exchanges the position of two overlay objects.
-
- insertOverlay:aboveOverlay:
Inserts one overlay object on top of another.
-
- insertOverlay:atIndex:
Inserts an overlay object into the list associated with the map.
-
- insertOverlay:belowOverlay:
Inserts one overlay object below another.
-
- mapRectThatFits:
Adjusts the aspect ratio of the specified map rectangle to ensure that it fits in the map view’s frame.
-
- mapRectThatFits:edgePadding:
Adjusts the aspect ratio of the specified map rectangle, incorporating the specified inset values.
-
- regionThatFits:
Adjusts the aspect ratio of the specified region to ensure that it fits in the map view’s frame.
-
- removeAnnotation:
Removes the specified annotation object from the map view.
-
- removeAnnotations:
Removes an array of annotation objects from the map view.
-
- removeOverlay:
Removes a single overlay object from the map.
-
- removeOverlays:
Removes one or more overlay objects from the map.
-
- selectAnnotation:animated:
Selects the specified annotation and displays a callout view for it.
-
- setCenterCoordinate:animated:
Changes the center coordinate of the map and optionally animates the change.
-
- setRegion:animated:
Changes the currently visible region and optionally animates the change.
-
- setUserTrackingMode:animated:
Sets the mode used to track the user location with optional animation.
-
- setVisibleMapRect:animated:
Changes the currently visible portion of the map and optionally animates the change.
-
- setVisibleMapRect:edgePadding:animated:
Changes the currently visible portion of the map, allowing you to specify additional space around the edges.
-
- viewForAnnotation:
Returns the annotation view associated with the specified annotation object, if any.
-
- viewForOverlay:
Returns the view associated with the overlay object if any.
Methods inherited from UIView
#addConstraint:, #addConstraints:, #addGestureRecognizer:, #addSubview:, #alignmentRectForFrame:, #alignmentRectInsets, animateWithDuration:animations:, animateWithDuration:animations:completion:, animateWithDuration:delay:options:animations:completion:, areAnimationsEnabled, beginAnimations:context:, #bringSubviewToFront:, commitAnimations, #constraints, #constraintsAffectingLayoutForAxis:, #contentCompressionResistancePriorityForAxis:, #contentHuggingPriorityForAxis:, #convertPoint:fromView:, #convertPoint:toView:, #convertRect:fromView:, #convertRect:toView:, #decodeRestorableStateWithCoder:, #didAddSubview:, #didMoveToSuperview, #didMoveToWindow, #drawRect:, #drawRect:forViewPrintFormatter:, #encodeRestorableStateWithCoder:, #endEditing:, #exchangeSubviewAtIndex:withSubviewAtIndex:, #exerciseAmbiguityInLayout, #frameForAlignmentRect:, #gestureRecognizerShouldBegin:, #hasAmbiguousLayout, #hitTest:withEvent:, #initWithFrame:, #insertSubview:aboveSubview:, #insertSubview:atIndex:, #insertSubview:belowSubview:, #intrinsicContentSize, #invalidateIntrinsicContentSize, #isDescendantOfView:, layerClass, #layoutIfNeeded, #layoutSubviews, #needsUpdateConstraints, #pointInside:withEvent:, #removeConstraint:, #removeConstraints:, #removeFromSuperview, #removeGestureRecognizer:, requiresConstraintBasedLayout, #sendSubviewToBack:, setAnimationBeginsFromCurrentState:, setAnimationCurve:, setAnimationDelay:, setAnimationDelegate:, setAnimationDidStopSelector:, setAnimationDuration:, setAnimationRepeatAutoreverses:, setAnimationRepeatCount:, setAnimationStartDate:, setAnimationTransition:forView:cache:, setAnimationWillStartSelector:, setAnimationsEnabled:, #setContentCompressionResistancePriority:forAxis:, #setContentHuggingPriority:forAxis:, #setNeedsDisplay, #setNeedsDisplayInRect:, #setNeedsLayout, #setNeedsUpdateConstraints, #setTranslatesAutoresizingMaskIntoConstraints:, #sizeThatFits:, #sizeToFit, #systemLayoutSizeFittingSize:, transitionFromView:toView:duration:options:completion:, transitionWithView:duration:options:animations:completion:, #translatesAutoresizingMaskIntoConstraints, #updateConstraints, #updateConstraintsIfNeeded, #viewForBaselineLayout, #viewPrintFormatter, #viewWithTag:, #willMoveToSuperview:, #willMoveToWindow:, #willRemoveSubview:
Methods inherited from UIResponder
#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Attribute Details
- (Array) annotations (readonly)
The complete list of annotations associated with the receiver. (read-only) The objects in this array must adopt the MKAnnotation protocol. If no annotations are associated with the map view, the value of this property is nil.
- (CGRect) annotationVisibleRect (readonly)
The visible rectangle where annotation views are currently being displayed. (read-only)
- (CLLocationCoordinate2D) centerCoordinate
The map coordinate at the center of the map view. Changing the value in this property centers the map on the new coordinate without changing the current zoom level. It also updates the values in the region property to reflect the new center coordinate and the new span values needed to maintain the current zoom level.Changing the value of this property updates the map view immediately. If you want to animate the change, use the setCenterCoordinate:animated: method instead.
- (Object) delegate
The receiver’s delegate. A map view sends messages to its delegate regarding the loading of map data and changes in the portion of the map being displayed. The delegate also manages the annotation views used to highlight points of interest on the map. The delegate should implement the methods of the MKMapViewDelegate protocol.
- (MKMapType) mapType
The type of data displayed by the map view. Changing the value in this property may cause the receiver to begin loading new map content. For example, changing from MKMapTypeStandard to MKMapTypeSatellite might cause it to begin loading the satellite imagery needed for the map. If new data is needed, however, it is loaded asynchronously and appropriate messages are sent to the receiver’s delegate indicating the status of the operation.
- (Array) overlays (readonly)
The overlay objects currently associated with the map view. (read-only) The objects in this array must adopt the MKOverlay protocol. If no overlays are associated with the map view, the value of this property is an empty array. If the regions defined by two overlays intersect one another, the order of the objects in this array determines the z-order of the corresponding overlay views that are displayed in the map. Overlay objects at the beginning of the array are placed behind those that come later in the array. Thus, the view for an overlay at index 0 is displayed behind the view for the overlay at index 1.
- (MKCoordinateRegion) region
The area currently displayed by the map view. The region encompasses both the latitude and longitude point on which the map is centered and the span of coordinates to display. The span values provide an implicit zoom value for the map. The larger the displayed area, the lower the amount of zoom. Similarly, the smaller the displayed area, the greater the amount of zoom. Changing only the center coordinate of the region can still cause the span to change implicitly. The span might change because the distances represented by a span change at different latitudes and longitudes and the map view may need to adjust the span to account for the new location. If you want to change the center coordinate without changing the zoom level, use the centerCoordinate instead.Changing the value of this property updates the map view immediately. When setting this property, the map may adjust the new region value so that it fits the visible area of the map precisely. This is normal and is done to ensure that the value in this property always reflects the visible portion of the map. However, it does mean that if you get the value of this property right after setting it, the returned value may not match the value you set. (You can use the regionThatFits: method to determine the region that will actually be set by the map.) If you want to animate the change in region, use the setRegion:animated: method instead.
- (Boolean) scrollEnabled
A Boolean value that determines whether the user may scroll around the map. This property controls only user interactions with the map. If you set the value of this property to NO, you may still change the map location programmatically by changing the value in the region property. The default value of this property is YES.
- (Array) selectedAnnotations
The annotations that are currently selected. Assigning a new array to this property selects only the first annotation in the array.
- (Boolean) showsUserLocation
A Boolean value indicating whether the map may display the user location. This property does not indicate whether the user’s position is actually visible on the map, only whether the map view is allowed to display it. To determine whether the user’s position is visible, use the userLocationVisible property. The default value of this property is NO.Setting this property to YES causes the map view to use the Core Location framework to find the current location. As long as this property is YES, the map view continues to track the user’s location and update it periodically.
- (MKUserLocation) userLocation (readonly)
The annotation object representing the user’s current location. (read-only)
- (Boolean) userLocationVisible (readonly)
A Boolean value indicating whether the device’s current location is visible in the map view. (read-only) This property uses the horizontal accuracy of the current location to determine whether the user’s location is visible. Thus, this property is YES if the specific coordinate is offscreen but the rectangle surrounding that coordinate (and defined by the horizontal accuracy value) is partially onscreen.If the user’s location cannot be determined, this property contains the value NO.
- (MKUserTrackingMode) userTrackingMode
The mode used to track the user location. Possible values are described in “MKUserTrackingMode.”
- (MKMapRect) visibleMapRect
The area currently displayed by the map view. This property represents the same basic information as the region property but specified as a map rectangle instead of a region. Changing the value of this property updates the map view immediately. If you want to animate the change, use the setVisibleMapRect:animated: method instead.
- (Boolean) zoomEnabled
A Boolean value that determines whether the user may use pinch gestures to zoom in and out of the map. This property controls only user interactions with the map. If you set the value of this property to NO, you may still change the zoom level programmatically by changing the value in the region property. The default value of this property is YES.
Instance Method Details
- (Object) addAnnotation(annotation)
Adds the specified annotation to the map view.
- (Object) addAnnotations(annotations)
Adds an array of annotation objects to the map view.
- (Object) addOverlay(overlay)
Adds a single overlay object to the map. The specified overlay is added to the end of the list of overlay objects. Adding an overlay causes the map view to begin monitoring the area represented by that overlay. As soon as the bounding rectangle of the overlay intersects the visible portion of the map, the map view adds a corresponding overlay view to the map. The overlay view is provided by the mapView:viewForOverlay: method of the map view’s delegate object. To remove an overlay from a map, you must remove the overlay object using the removeOverlay: method.
- (Object) addOverlays(overlays)
Adds an array of overlay objects to the map. The specified objects are added to the end of the list of overlay objects. Adding an overlay causes the map view to begin monitoring the area represented by that overlay. As soon as the bounding rectangle of the overlay intersects the visible portion of the map, the map view adds a corresponding overlay view to the map. The overlay view is provided by the mapView:viewForOverlay: method of the map view’s delegate object. To remove an overlay from a map, you must remove the overlay object using the removeOverlay: method.
- (NSSet) annotationsInMapRect(mapRect)
Returns the annotation objects located in the specified map rectangle. This method offers a fast way to retrieve the annotation objects in a particular portion of the map. This method is much faster than doing a linear search of the objects in the annotations property yourself.
- (CGPoint) convertCoordinate(coordinate, toPointToView:view)
Converts a map coordinate to a point in the specified view.
- (CLLocationCoordinate2D) convertPoint(point, toCoordinateFromView:view)
Converts a point in the specified view’s coordinate system to a map coordinate.
- (MKCoordinateRegion) convertRect(rect, toRegionFromView:view)
Converts a rectangle in the specified view’s coordinate system to a map region.
- (CGRect) convertRegion(region, toRectToView:view)
Converts a map region to a rectangle in the specified view.
- (MKAnnotationView) dequeueReusableAnnotationViewWithIdentifier(identifier)
Returns a reusable annotation view located by its identifier. For performance reasons, you should generally reuse MKAnnotationView objects in your map views. As annotation views move offscreen, the map view moves them to an internally managed reuse queue. As new annotations move onscreen, and your code is prompted to provide a corresponding annotation view, you should always attempt to dequeue an existing view before creating a new one. Dequeueing saves time and memory during performance-critical operations such as scrolling.
- (Object) deselectAnnotation(annotation, animated:animated)
Deselects the specified annotation and hides its callout view.
- (Object) exchangeOverlayAtIndex(index1, withOverlayAtIndex:index2)
Exchanges the position of two overlay objects. If either overlay object has an associated view, the position of that view is updated as well. Thus, exchanging views also affects the z-order of overlay views as they appear on the map view.
- (Object) insertOverlay(overlay, aboveOverlay:sibling)
Inserts one overlay object on top of another. This method adds the object in overlay to the map view and positions it relative to the specified sibling object in the overlays array. This position causes the view associated with overlay to be displayed on top of the view associated with sibling.
- (Object) insertOverlay(overlay, atIndex:index)
Inserts an overlay object into the list associated with the map.
- (Object) insertOverlay(overlay, belowOverlay:sibling)
Inserts one overlay object below another. This method adds the object in overlay to the map view and positions it relative to the specified sibling object in the overlays array. This position causes the view associated with overlay to be displayed behind the view associated with sibling.
- (MKMapRect) mapRectThatFits(mapRect)
Adjusts the aspect ratio of the specified map rectangle to ensure that it fits in the map view’s frame. You can use this method to normalize map rectangle values before displaying the corresponding area. This method returns a new map rectangle that both contains the specified rectangle and fits neatly inside the map view’s frame.
- (MKMapRect) mapRectThatFits(mapRect, edgePadding:insets)
Adjusts the aspect ratio of the specified map rectangle, incorporating the specified inset values.
- (MKCoordinateRegion) regionThatFits(region)
Adjusts the aspect ratio of the specified region to ensure that it fits in the map view’s frame. You can use this method to normalize the region values before displaying them in the map. This method returns a new region that both contains the specified region and fits neatly inside the map view’s frame.
- (Object) removeAnnotation(annotation)
Removes the specified annotation object from the map view. If the annotation is currently associated with an annotation view, and that view has a reuse identifier, this method removes the annotation view and queues it internally for later reuse. You can retrieve queued annotation views (and associate them with new annotations) using the dequeueReusableAnnotationViewWithIdentifier: method. Removing an annotation object disassociates it from the map view entirely, preventing it from being displayed on the map. Thus, you would typically call this method only when you want to hide or delete a given annotation.
- (Object) removeAnnotations(annotations)
Removes an array of annotation objects from the map view. If any annotation object in the array has an associated annotation view, and if that view has a reuse identifier, this method removes the annotation view and queues it internally for later reuse. You can retrieve queued annotation views (and associate them with new annotations) using the dequeueReusableAnnotationViewWithIdentifier: method. Removing annotation objects disassociates them from the map view entirely, preventing them from being displayed on the map. Thus, you would typically call this method only when you want to hide or delete the specified annotations.
- (Object) removeOverlay(overlay)
Removes a single overlay object from the map. Removing an overlay object removes the corresponding overlay view, if one is currently displayed. If the specified object is not currently associated with the map view, this method does nothing.
- (Object) removeOverlays(overlays)
Removes one or more overlay objects from the map. Removing an overlay object removes the corresponding overlay view, if one is currently displayed. If one or more of the overlay objects are not currently associated with the map view, this method removes the objects that are associated with the map and ignores the rest.
- (Object) selectAnnotation(annotation, animated:animated)
Selects the specified annotation and displays a callout view for it. If the specified annotation is not onscreen, and therefore does not have an associated annotation view, this method has no effect.
- (Object) setCenterCoordinate(coordinate, animated:animated)
Changes the center coordinate of the map and optionally animates the change. Changing the center coordinate centers the map on the new coordinate without changing the current zoom level. It also updates the values in the region property to reflect the new center coordinate and the new span values needed to maintain the current zoom level.
- (Object) setRegion(region, animated:animated)
Changes the currently visible region and optionally animates the change. Changing just the center coordinate of the region can still cause the span values to change implicitly. The span values might change because that the distances represented by a span change at different latitudes and longitudes and the map view may need to adjust the span to account for the new location. If you want to change the center coordinate without changing the zoom level, use the setCenterCoordinate:animated: instead.When setting a new region, the map may adjust the value in the region parameter so that it fits the visible area of the map precisely. This adjustment is normal and is done to ensure that the value in the region property always reflects the visible portion of the map. However, it does mean that if you get the value of that property right after calling this method, the returned value may not match the value you set. (You can use the regionThatFits: method to determine the region that will actually be set by the map.)
- (Object) setUserTrackingMode(mode, animated:animated)
Sets the mode used to track the user location with optional animation.
- (Object) setVisibleMapRect(mapRect, animated:animate)
Changes the currently visible portion of the map and optionally animates the change.
- (Object) setVisibleMapRect(mapRect, edgePadding:insets, animated:animate)
Changes the currently visible portion of the map, allowing you to specify additional space around the edges.
- (MKAnnotationView) viewForAnnotation(annotation)
Returns the annotation view associated with the specified annotation object, if any.
- (MKOverlayView) viewForOverlay(overlay)
Returns the view associated with the overlay object if any.