Anda di halaman 1dari 51

MKMapView Class Reference

Contents

MKMapView Class Reference 5


Overview 5 Annotating the Map 6 Adding Overlays to the Map 7 Tasks 8 Accessing Map Properties 8 Accessing the Delegate 8 Manipulating the Visible Portion of the Map 8 Configuring the Maps Appearance 9 Displaying the Users Location 9 Annotating the Map 10 Managing Annotation Selections 10 Accessing Overlays 10 Adding and Inserting Overlays 11 Removing Overlays 12 Converting Map Coordinates 12 Adjusting Map Regions and Rectangles 12 Properties 12 annotations 12 annotationVisibleRect 13 camera 13 centerCoordinate 14 delegate 14 mapType 15 overlays 15 pitchEnabled 16 region 16 rotateEnabled 17 scrollEnabled 18 selectedAnnotations 18 showsBuildings 18 showsPointsOfInterest 19 showsUserLocation 19 userLocation 20

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

Contents

userLocationVisible 20 userTrackingMode 21 visibleMapRect 21 zoomEnabled 22 Instance Methods 22 addAnnotation: 22 addAnnotations: 23 addOverlay: 23 addOverlay:level: 24 addOverlays: 25 addOverlays:level: 26 annotationsInMapRect: 26 convertCoordinate:toPointToView: 27 convertPoint:toCoordinateFromView: 28 convertRect:toRegionFromView: 28 convertRegion:toRectToView: 29 dequeueReusableAnnotationViewWithIdentifier: 30 deselectAnnotation:animated: 30 exchangeOverlay:withOverlay: 31 exchangeOverlayAtIndex:withOverlayAtIndex: 31 insertOverlay:aboveOverlay: 32 insertOverlay:atIndex: 33 insertOverlay:atIndex:level: 33 insertOverlay:belowOverlay: 34 mapRectThatFits: 35 mapRectThatFits:edgePadding: 35 overlaysInLevel: 36 regionThatFits: 37 removeAnnotation: 37 removeAnnotations: 38 removeOverlay: 39 removeOverlays: 39 rendererForOverlay: 40 selectAnnotation:animated: 40 setCamera:animated: 41 setCenterCoordinate:animated: 41 setRegion:animated: 42 setUserTrackingMode:animated: 43 setVisibleMapRect:animated: 44

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

Contents

setVisibleMapRect:edgePadding:animated: 44 showAnnotations:animated: 45 viewForAnnotation: 46 Constants 46 MKMapType 46 MKUserTrackingMode 47 MKOverlayLevel 47

Deprecated MKMapView Methods 49


Deprecated in iOS 7.0 49 viewForOverlay: 49

Document Revision History 50

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference

Inherits from Conforms to

UIView : UIResponder : NSObject NSCoding NSCoding (UIView) UIAppearance (UIView) UIAppearanceContainer (UIView) UIDynamicItem (UIView) NSObject (NSObject)

Framework Availability Companion guide Declared in

/System/Library/Frameworks/MapKit.framework Available in iOS 3.0 and later. Location and Maps Programming Guide MKMapView.h MKTypes.h

Related sample code

Breadcrumb KMLViewer MapCallouts PhotosByLocation Regions

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.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference Overview

Important: In iOS 5.1 and earlier, the Map Kit framework uses the Google Mobile Maps (GMM) service to provide map data. Use of specific classes of this framework (and their associated interfaces) is subject to the Google Mobile Maps terms of service. You can find these terms of service at http://code.google.com/apis/maps/iphone/terms.html. When you initialize a map view, you should specify the initial region for that map to display. You do this by setting the region (page 16) property of the map. A region is defined by a center point and a horizontal and vertical distance, referred to as the span. The span defines how much of the map at the given point should be visible and is also how you set the zoom level. Specifying a large span results in the user seeing a wide geographical area and corresponds to a low zoom level. Specifying a small span results in the user seeing a more narrow geographical area and corresponds to a higher zoom level. In addition to setting the span programmatically, the MKMapView class supports many standard interactions for changing the position and zoom level of the map. In particular, map views support flick and pinch gestures for scrolling around the map and zooming in and out. Support for these gestures is enabled by default but can also be disabled using the scrollEnabled (page 18) and zoomEnabled (page 22) properties. You can also use projected map coordinates instead of regions to specify some values. When you project the curved surface of the globe onto a flat surface, you get a two-dimensional version of a map where longitude lines appear to be parallel. To specify locations and distances, you use the MKMapPoint, MKMapSize, and MKMapRect data types. Although you should not subclass the MKMapView class itself, you can get information about the map views behavior by providing a delegate object. The map view calls the methods of your custom delegate to let it know about changes in the map status and to coordinate the display of custom annotations, which are described in more detail in Annotating the Map (page 6). The delegate object can be any object in your application as long as it conforms to the MKMapViewDelegate protocol. For more information about implementing the delegate object, see MKMapViewDelegate Protocol Reference .

Annotating the Map


The MKMapView class supports the ability to annotate the map with custom information. Because a map may have potentially large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map. An annotation object is any object that conforms to the MKAnnotation protocol. Annotation objects are typically implemented using existing classes in your applications data model. This allows you to manipulate the annotation data directly but still make it available to the map view. Each annotation object contains information about the annotations location on the map along with descriptive information that can be displayed in a callout.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference Overview

The presentation of annotation objects on the screen is handled by an annotation view, which is an instance of the MKAnnotationView class. An annotation view is responsible for presenting the annotation data in a way that makes sense. For example, the Maps application uses a pin icon to denote specific points of interest on a map. (The Map Kit framework offers the MKPinAnnotationView class for similar annotations in your own applications.) You could also create annotation views that cover larger portions of the map. Because annotation views are needed only when they are onscreen, the MKMapView class provides a mechanism for queueing annotation views that are not in use. Annotation views with a reuse identifier can be detached and queued internally by the map view when they move offscreen. This feature improves memory use by keeping only a small number of annotation views in memory at once and by recycling the views you do have. It also improves scrolling performance by alleviating the need to create new views while the map is scrolling. When configuring your map interface, you should add all of your annotation objects right away. The map view uses the coordinate data in each annotation object to determine when the corresponding annotation view needs to appear onscreen. When an annotation moves onscreen, the map view asks its delegate to create a corresponding annotation view. If your application has different types of annotations, it can define different annotation view classes to represent each type.

Adding Overlays to the Map


You can use overlays to layer content over a wide portion of the map. An overlay object is any object that conforms to the MKOverlay protocol. An overlay object is a data object that contains the points needed to specify the shape and size of the overlay and its location on the map. Overlays can represent shapes such as circles, rectangles, multi-segment lines, and simple or complex polygons. You can also define your own custom overlays to represent other shapes. In iOS 7 and later, the presentation of an overlay is handled by an overlay renderer object, which is an instance of the MKOverlayRenderer class. The job of the renderer is to draw the overlays content onto the screen when asked to do so by the map view. For example, if you have a simple overlay that represents a bus route, you could use a polyline renderer to draw the line segments that trace the route of the bus. You could also define a custom renderer that draws both the bus route and icons at the location of each bus stop. When specifying overlays, you can add them to specific levels of the map, which allows them to be rendered above or below other types of map content. Prior to iOS 7, overlays are drawn on onscreen using overlay views, which are instances of the MKOverlayView class. When configuring your map interface, you can add overlay objects at any time. The map view uses the data in each overlay object to determine when the corresponding overlay view needs to appear onscreen. When an overlay moves onscreen, the map view asks its delegate to create a corresponding overlay renderer.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference Tasks

Tasks
Accessing Map Properties
mapType

(page 15) property The type of data displayed by the map view. (page 22) property A Boolean value that determines whether the user may use pinch gestures to zoom in and out of the map. (page 18) property A Boolean value that determines whether the user may scroll around the map. (page 16) property A Boolean value indicating whether the map cameras pitch information is used. (page 17) property A Boolean value indicating whether the map cameras heading information is used.

zoomEnabled

scrollEnabled

pitchEnabled

rotateEnabled

Accessing the Delegate


delegate

(page 14) property The receivers delegate.

Manipulating the Visible Portion of the Map


region

(page 16) property The area currently displayed by the map view. (page 42) Changes the currently visible region and optionally animates the change. (page 14) property The map coordinate at the center of the map view. (page 41) Changes the center coordinate of the map and optionally animates the change. (page 45) Sets the visible region so that the map displays the specified annotations.

setRegion:animated:

centerCoordinate

setCenterCoordinate:animated:

showAnnotations:animated:

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference Tasks

visibleMapRect

(page 21) property The area currently displayed by the map view. (page 44) Changes the currently visible portion of the map and optionally animates the change. (page 44) Changes the currently visible portion of the map, allowing you to specify additional space around the edges.

setVisibleMapRect:animated:

setVisibleMapRect:edgePadding:animated:

Configuring the Maps Appearance


camera

(page 13) property The camera used for determining the appearance of the map. (page 41) Changes the camera used for determining the maps viewing parameters and optionally animates the change. (page 19) property A Boolean indicating whether the map displays point-of-interest information. (page 18) property A Boolean indicating whether the map displays extruded building information.

setCamera:animated:

showsPointsOfInterest

showsBuildings

Displaying the Users Location


showsUserLocation

(page 19) property A Boolean value indicating whether the map should try to display the users location. (page 20) property A Boolean value indicating whether the devices current location is visible in the map view. (read-only) (page 20) property The annotation object representing the users current location. (read-only) (page 21) property The mode used to track the user location. (page 43) Sets the mode used to track the user location with optional animation.

userLocationVisible

userLocation

userTrackingMode

setUserTrackingMode:animated:

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

MKMapView Class Reference Tasks

Annotating the Map


annotations

(page 12) property The complete list of annotations associated with the receiver. (read-only) (page 22) Adds the specified annotation to the map view. (page 23) Adds an array of annotation objects to the map view. (page 37) Removes the specified annotation object from the map view. (page 38) Removes an array of annotation objects from the map view. (page 46) Returns the annotation view associated with the specified annotation object, if any. (page 26) Returns the annotation objects located in the specified map rectangle. (page 13) property The visible rectangle where annotation views are currently being displayed. (read-only) (page 30) Returns a reusable annotation view located by its identifier.

addAnnotation:

addAnnotations:

removeAnnotation:

removeAnnotations:

viewForAnnotation:

annotationsInMapRect:

annotationVisibleRect

dequeueReusableAnnotationViewWithIdentifier:

Managing Annotation Selections


selectedAnnotations

(page 18) property The annotations that are currently selected. (page 40) Selects the specified annotation and displays a callout view for it. (page 30) Deselects the specified annotation and hides its callout view.

selectAnnotation:animated:

deselectAnnotation:animated:

Accessing Overlays
overlays

(page 15) property The overlay objects currently associated with the map view. (read-only)

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

10

MKMapView Class Reference Tasks

overlaysInLevel:

(page 36) The overlay objects in the specified level of the map. (page 40) Returns the renderer object used to draw the contents of the specified overlay object. (page 49) Deprecated in iOS 7.0 Returns the view associated with the overlay object if any. (Deprecated. Use the rendererForOverlay: (page 40) method instead.)

rendererForOverlay:

viewForOverlay:

Adding and Inserting Overlays


addOverlay:level:

(page 24) Adds the overlay object to the map at the specified level. (page 26) Adds an array of overlay objects to the map at the specified level. (page 23) Adds a single overlay object to the map. (page 25) Adds an array of overlay objects to the map. (page 33) Inserts an overlay object into the level at the specified index. (page 33) Inserts an overlay object into the list associated with the map. (page 32) Inserts one overlay object on top of another. (page 34) Inserts one overlay object below another. (page 31) Exchanges the positions of the two overlay objects. (page 31) Exchanges the position of two overlay objects.

addOverlays:level:

addOverlay:

addOverlays:

insertOverlay:atIndex:level:

insertOverlay:atIndex:

insertOverlay:aboveOverlay:

insertOverlay:belowOverlay:

exchangeOverlay:withOverlay:

exchangeOverlayAtIndex:withOverlayAtIndex:

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

11

MKMapView Class Reference Properties

Removing Overlays
removeOverlay:

(page 39) Removes a single overlay object from the map. (page 39) Removes one or more overlay objects from the map.

removeOverlays:

Converting Map Coordinates


convertCoordinate:toPointToView:

(page 27) Converts a map coordinate to a point in the specified view. (page 28) Converts a point in the specified views coordinate system to a map coordinate. (page 29) Converts a map region to a rectangle in the specified view. (page 28) Converts a rectangle in the specified views coordinate system to a map region.

convertPoint:toCoordinateFromView:

convertRegion:toRectToView:

convertRect:toRegionFromView:

Adjusting Map Regions and Rectangles


regionThatFits:

(page 37) Adjusts the aspect ratio of the specified region to ensure that it fits in the map views frame. (page 35) Adjusts the aspect ratio of the specified map rectangle to ensure that it fits in the map views frame. (page 35) Adjusts the aspect ratio of the specified map rectangle, incorporating the specified inset values.

mapRectThatFits:

mapRectThatFits:edgePadding:

Properties
annotations
The complete list of annotations associated with the receiver. (read-only)

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

12

MKMapView Class Reference Properties

@property(nonatomic, readonly) NSArray *annotations

Discussion 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. Availability Available in iOS 3.0 and later. See Also (page 22) addAnnotations: (page 23) removeAnnotation: (page 37) removeAnnotations: (page 38)
addAnnotation:

Declared in
MKMapView.h

annotationVisibleRect
The visible rectangle where annotation views are currently being displayed. (read-only)
@property(nonatomic, readonly) CGRect annotationVisibleRect

Availability Available in iOS 3.0 and later. Declared in


MKMapView.h

camera
The camera used for determining the appearance of the map.
@property(nonatomic, copy) MKMapCamera *camera

Discussion A camera object defines a point above the maps surface from which to view the map. Applying a camera to a map has the effect of giving the map a 3D-like appearance. You can use a camera to rotate the map so that it is oriented to match the users heading or to apply a pitch angle to tilt the plane of the map. Assigning a new camera to this property updates the map immediately and without animating the change. If you want to animate changes in camera position, use the setCamera:animated: (page 41) method instead.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

13

MKMapView Class Reference Properties

You must not set this property to nil. To restore the map to a flat appearance, apply a camera with a pitch angle of 0, which yields a camera looking straight down onto the map surface. Availability Available in iOS 7.0 and later. See Also
setCamera:animated:

(page 41)

Declared in
MKMapView.h

centerCoordinate
The map coordinate at the center of the map view.
@property(nonatomic) CLLocationCoordinate2D centerCoordinate

Discussion 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. Availability Available in iOS 3.0 and later. See Also
setCenterCoordinate:animated: @property region

(page 41)

(page 16)

Related Sample Code

Regions

Declared in
MKMapView.h

delegate
The receivers delegate.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

14

MKMapView Class Reference Properties

@property(nonatomic, assign) id<MKMapViewDelegate> delegate

Discussion 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. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

mapType
The type of data displayed by the map view.
@property(nonatomic) MKMapType mapType

Discussion 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 receivers delegate indicating the status of the operation. Availability Available in iOS 3.0 and later.
Related Sample Code

GeocoderDemo Declared in
MKMapView.h

overlays
The overlay objects currently associated with the map view. (read-only)

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

15

MKMapView Class Reference Properties

@property(nonatomic, readonly) NSArray *overlays

Discussion This property contains the union of all overlays at the different levels of the map. 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. The order of the objects in this array does not necessary reflect their visual order on the map. Availability Available in iOS 4.0 and later. Declared in
MKMapView.h

pitchEnabled
A Boolean value indicating whether the map cameras pitch information is used.
@property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled

Discussion When this property is set to YES and a valid camera is associated with the map, the cameras pitch angle is used to tilt the plane of the map. When this property is set to NO, the cameras pitch angle is ignored and the map is always displayed as if the user is looking straight down onto it. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

region
The area currently displayed by the map view.
@property(nonatomic) MKCoordinateRegion region

Discussion 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.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

16

MKMapView Class Reference Properties

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: (page 37) 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. Availability Available in iOS 3.0 and later. See Also
setRegion:animated:

(page 42) @property centerCoordinate (page 14)

Declared in
MKMapView.h

rotateEnabled
A Boolean value indicating whether the map cameras heading information is used.
@property(nonatomic, getter=isRotateEnabled) BOOL rotateEnabled

Discussion When this property is set to YES and a valid camera is associated with the map, the cameras heading angle is used to rotate the plane of the map around its center point. When this property is set to NO, the cameras heading angle is ignored and the map is always oriented so that true north is situated at the top of the map view. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

17

MKMapView Class Reference Properties

scrollEnabled
A Boolean value that determines whether the user may scroll around the map.
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled

Discussion 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. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

selectedAnnotations
The annotations that are currently selected.
@property(nonatomic, copy) NSArray *selectedAnnotations

Discussion Assigning a new array to this property selects only the first annotation in the array. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

showsBuildings
A Boolean indicating whether the map displays extruded building information.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

18

MKMapView Class Reference Properties

@property (nonatomic) BOOL showsBuildings;

Discussion When this property is set to YES and the camera has a pitch angle greater than zero, the map extrudes buildings so that they extend above the map plane, creating a 3D effect. The mapType (page 15) property must be set to MKMapTypeStandard (page 46) for extruded buildings to be displayed. The default value of this property is YES. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

showsPointsOfInterest
A Boolean indicating whether the map displays point-of-interest information.
@property (nonatomic) BOOL showsPointsOfInterest;

Discussion When this property is set to YES, the map displays icons and labels for restaurants, schools, and other relevant points of interest. The default value of this property is YES. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

showsUserLocation
A Boolean value indicating whether the map should try to display the users location.
@property(nonatomic) BOOL showsUserLocation

Discussion This property does not indicate whether the users position is actually visible on the map, only whether the map view should try to display it. Setting this property to YES causes the map view to use the Core Location framework to find the current location and try to display it on the map. As long as this property is YES, the map view continues to track the users location and update it periodically. The default value of this property is NO.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

19

MKMapView Class Reference Properties

Showing the users location does not guarantee that the location is visible on the map. The user might have scrolled the map to a different point, causing the current location to be offscreen. To determine whether the users current location is currently displayed on the map, use the userLocationVisible property. Availability Available in iOS 3.0 and later. See Also
@property userLocationVisible

(page 20)

Declared in
MKMapView.h

userLocation
The annotation object representing the users current location. (read-only)
@property(nonatomic, readonly) MKUserLocation *userLocation

Availability Available in iOS 3.0 and later. See Also


@property showsUserLocation

(page 19)

Declared in
MKMapView.h

userLocationVisible
A Boolean value indicating whether the devices current location is visible in the map view. (read-only)
@property(nonatomic, readonly, getter=isUserLocationVisible) BOOL userLocationVisible

Discussion This property tells you whether the icon used to represent the users current location is visible in the map view. When determining whether the current location is visible, this property factors in the horizontal accuracy of the location data. Specifically, if the rectangle represented by the users current location plus or minus minus the horizontal accuracy of that location intersects the maps visible rectangle, this property contains the value YES. If that location rectangle does not intersect the maps visible rectangle, this property contains the value NO.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

20

MKMapView Class Reference Properties

If the users location cannot be determined, this property contains the value NO. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

userTrackingMode
The mode used to track the user location.
@property(nonatomic) MKUserTrackingMode userTrackingMode

Discussion Possible values are described in MKUserTrackingMode (page 47). Setting the tracking mode to MKUserTrackingModeFollow (page 47) or MKUserTrackingModeFollowWithHeading (page 47) causes the map view to center the map on that location and begin tracking the users location. If the map is zoomed out, the map view automatically zooms in on the users location, effectively changing the current visible region. Availability Available in iOS 5.0 and later. See Also
setUserTrackingMode:animated:

(page 43)

Declared in
MKMapView.h

visibleMapRect
The area currently displayed by the map view.
@property(nonatomic) MKMapRect visibleMapRect

Discussion This property represents the same basic information as the region (page 16) 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.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

21

MKMapView Class Reference Instance Methods

Availability Available in iOS 4.0 and later.


Related Sample Code

KMLViewer PhotosByLocation Declared in


MKMapView.h

zoomEnabled
A Boolean value that determines whether the user may use pinch gestures to zoom in and out of the map.
@property(nonatomic, getter=isZoomEnabled) BOOL zoomEnabled

Discussion 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. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

Instance Methods
addAnnotation:
Adds the specified annotation to the map view.
- (void)addAnnotation:(id < MKAnnotation >)annotation

Parameters
annotation

The annotation object to add to the receiver. This object must conform to the MKAnnotation protocol. The map view retains the specified object.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

22

MKMapView Class Reference Instance Methods

Availability Available in iOS 3.0 and later. See Also (page 23) removeAnnotation: (page 37)
addAnnotations:

Related Sample Code

GeocoderDemo Regions Declared in


MKMapView.h

addAnnotations:
Adds an array of annotation objects to the map view.
- (void)addAnnotations:(NSArray *)annotations

Parameters
annotations

An array of annotation objects. Each object in the array must conform to the MKAnnotation protocol. The map view retains the individual annotation objects. Availability Available in iOS 3.0 and later. See Also (page 22) removeAnnotations: (page 38)
addAnnotation:

Declared in
MKMapView.h

addOverlay:
Adds a single overlay object to the map.
- (void)addOverlay:(id < MKOverlay >)overlay

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

23

MKMapView Class Reference Instance Methods

Parameters
overlay

The overlay object to add. This object must conform to the MKOverlay protocol. Discussion The specified object is added to the group of overlay objects in the MKOverlayLevelAboveLabels (page 48) level. Adding an overlay causes the map view to begin monitoring the area represented by that overlay. As soon as the bounding rectangle of an 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 views delegate object. To remove an overlay from a map, use the removeOverlay: (page 39) method. Availability Available in iOS 4.0 and later. See Also (page 25) removeOverlay: (page 39) removeOverlays: (page 39)
addOverlays:

Related Sample Code

Regions

Declared in
MKMapView.h

addOverlay:level:
Adds the overlay object to the map at the specified level.
- (void)addOverlay:(id < MKOverlay >)overlay level:(MKOverlayLevel)level

Parameters
overlay

The overlay object to add. This object must conform to the MKOverlay protocol.
level

The map level at which to place the overlay. For a list of possible values for this parameter, see MKOverlayLevel (page 47).

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

24

MKMapView Class Reference Instance Methods

Discussion Positioning an overlay at a specific level places that overlays visual representation in front of or behind other map content such as map labels and point-of-interest icons. This method adds the specified overlay to the end of the list of overlay objects at the given level. Adding an overlay also causes the map view to begin monitoring the area they represent. As soon as the bounding rectangle of the overlay intersects the visible portion of the map, the map view calls your delegates mapView:rendererForOverlay: method to get the renderer object to use when drawing the overlay. To remove an overlay from a map, use the removeOverlay: (page 39) method. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

addOverlays:
Adds an array of overlay objects to the map.
- (void)addOverlays:(NSArray *)overlays

Parameters
overlays

An array of objects, each of which must conform to the MKOverlay protocol. Discussion The specified objects are added to the group of overlay objects in the MKOverlayLevelAboveLabels (page 48) level. 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 tries to draw the overlay. As soon as the bounding rectangle of an 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 views delegate object. To remove multiple overlays from a map, use the removeOverlays: (page 39) method. Availability Available in iOS 4.0 and later. See Also
addOverlay: removeOverlay:

(page 23) (page 39)

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

25

MKMapView Class Reference Instance Methods

removeOverlays:

(page 39)

Declared in
MKMapView.h

addOverlays:level:
Adds an array of overlay objects to the map at the specified level.
- (void)addOverlays:(NSArray *)overlays level:(MKOverlayLevel)level

Parameters
overlays

The array of overlay objects to add. Each object in the array must conform to the MKOverlay protocol.
level

The map level at which to place the overlays. For a list of possible values for this parameter, see MKOverlayLevel (page 47). Discussion Positioning an overlay at a specific level places that overlays visual representation in front of or behind other map content such as map labels and point-of-interest icons. This method adds the specified overlays to the end of the list of overlay objects at the given level. Adding the overlays also causes the map view to begin monitoring the area they represent. As soon as the bounding rectangle of an overlay intersects the visible portion of the map, the map view calls your delegates mapView:rendererForOverlay: method to get the renderer object to use when drawing that overlay. To remove multiple overlays from a map, use the removeOverlays: (page 39) method. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

annotationsInMapRect:
Returns the annotation objects located in the specified map rectangle.
- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

26

MKMapView Class Reference Instance Methods

Parameters
mapRect

The portion of the map that you want to search for annotations. Return Value The set of annotation objects located in mapRect. Discussion 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 (page 12) property yourself. Special Considerations Prior to iOS 7 this method incorrectly did not return instances of MKUserLocation. Availability Available in iOS 4.2 and later. Declared in
MKMapView.h

convertCoordinate:toPointToView:
Converts a map coordinate to a point in the specified view.
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView

*)view

Parameters
coordinate

The map coordinate for which you want to find the corresponding point.
view

The view in whose coordinate system you want to locate the specified map coordinate. If this parameter is nil, the returned point is specified in the windows coordinate system. If view is not nil, it must belong to the same window as the map view. Return Value The point (in the appropriate view or window coordinate system) corresponding to the specified latitude and longitude value. Availability Available in iOS 3.0 and later.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

27

MKMapView Class Reference Instance Methods

See Also
convertPoint:toCoordinateFromView:

(page 28)

Declared in
MKMapView.h

convertPoint:toCoordinateFromView:
Converts a point in the specified views coordinate system to a map coordinate.
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView

*)view

Parameters
point

The point you want to convert.


view

The view that serves as the reference coordinate system for the point parameter. Return Value The map coordinate at the specified point. Availability Available in iOS 3.0 and later. See Also
convertCoordinate:toPointToView:

(page 27)

Declared in
MKMapView.h

convertRect:toRegionFromView:
Converts a rectangle in the specified views coordinate system to a map region.
- (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(UIView *)view

Parameters
rect

The rectangle you want to convert.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

28

MKMapView Class Reference Instance Methods

view

The view that serves as the reference coordinate system for the rect parameter. Return Value The map region corresponding to the specified view rectangle. Availability Available in iOS 3.0 and later. See Also
convertRegion:toRectToView:

(page 29)

Declared in
MKMapView.h

convertRegion:toRectToView:
Converts a map region to a rectangle in the specified view.
- (CGRect)convertRegion:(MKCoordinateRegion)region toRectToView:(UIView *)view

Parameters
region

The map region for which you want to find the corresponding view rectangle.
view

The view in whose coordinate system you want to locate the specified map region. If this parameter is nil, the returned rectangle is specified in the windows coordinate system. If view is not nil, it must belong to the same window as the map view. Return Value The rectangle corresponding to the specified map region. Availability Available in iOS 3.0 and later. See Also
convertRect:toRegionFromView:

(page 28)

Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

29

MKMapView Class Reference Instance Methods

dequeueReusableAnnotationViewWithIdentifier:
Returns a reusable annotation view located by its identifier.
- (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString

*)identifier

Parameters
identifier

A string identifying the annotation view to be reused. This string is the same one you specify when initializing the annotation view using the initWithAnnotation:reuseIdentifier: method. Return Value An annotation view with the specified identifier, or nil if no such object exists in the reuse queue. Discussion 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. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

deselectAnnotation:animated:
Deselects the specified annotation and hides its callout view.
- (void)deselectAnnotation:(id < MKAnnotation >)annotation animated:(BOOL)animated

Parameters
annotation

The annotation object to deselect.


animated

If YES, the callout view is animated offscreen. Availability Available in iOS 3.0 and later.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

30

MKMapView Class Reference Instance Methods

Declared in
MKMapView.h

exchangeOverlay:withOverlay:
Exchanges the positions of the two overlay objects.
- (void)exchangeOverlay:(id < MKOverlay >)overlay1 withOverlay:(id < MKOverlay

>)overlay2

Parameters
overlay1

The first overlay object.


overlay2

The second overlay object. Discussion If the overlays are in the same map level, they exchange positions within that levels array of overlay objects. If they are in different map levels, the two objects also swap levels. Swapping the position of the overlays affects their visibility in the map view. Availability Available in iOS 7.0 and later. See Also
exchangeOverlayAtIndex:withOverlayAtIndex:

(page 31)

Declared in
MKMapView.h

exchangeOverlayAtIndex:withOverlayAtIndex:
Exchanges the position of two overlay objects.
- (void)exchangeOverlayAtIndex:(NSUInteger)index1

withOverlayAtIndex:(NSUInteger)index2

Parameters
index1

The index of an overlay in the MKOverlayLevelAboveLabels (page 48) map level.


index2

The index of another overlay in the MKOverlayLevelAboveLabels map level.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

31

MKMapView Class Reference Instance Methods

Discussion If you need to exchange overlays in other map levels, use the exchangeOverlay:withOverlay: method. Availability Available in iOS 4.0 and later. See Also
exchangeOverlay:withOverlay:

(page 31)

Declared in
MKMapView.h

insertOverlay:aboveOverlay:
Inserts one overlay object on top of another.
- (void)insertOverlay:(id < MKOverlay >)overlay aboveOverlay:(id < MKOverlay >)sibling

Parameters
overlay

The overlay object to insert.


sibling

An existing object in the overlays array. This object must exist in the array and must not be nil. Discussion This method inserts the overlay into the MKOverlayLevelAboveLabels (page 48) level and positions it relative to the specified sibling. When displayed, this leads to the overlays contents being displayed above that of its sibling. If sibling is not in the same map level, this method appends the overlay to the end of the list of overlays at the indicated level. Availability Available in iOS 4.0 and later. See Also (page 33) insertOverlay:belowOverlay: (page 34)
insertOverlay:atIndex:

Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

32

MKMapView Class Reference Instance Methods

insertOverlay:atIndex:
Inserts an overlay object into the list associated with the map.
- (void)insertOverlay:(id < MKOverlay >)overlay atIndex:(NSUInteger)index

Parameters
overlay

The overlay object to insert.


index

The index at which to insert the overlay object. If this value is greater than the number of objects in the overlays (page 15) property, this method appends the object to the end of the array. Discussion This method inserts the overlay into the MKOverlayLevelAboveLabels (page 48) level. Availability Available in iOS 4.0 and later. See Also (page 32) insertOverlay:belowOverlay: (page 34)
insertOverlay:aboveOverlay:

Declared in
MKMapView.h

insertOverlay:atIndex:level:
Inserts an overlay object into the level at the specified index.
- (void)insertOverlay:(id < MKOverlay >)overlay atIndex:(NSUInteger)index

level:(MKOverlayLevel)level

Parameters
overlay

The overlay object to insert.


index

The index at which to insert the overlay object. If this value is greater than the number of objects in the overlays (page 15) property, this method appends the object to the end of the array.
level

The map level at which to place the overlay. For a list of possible values for this parameter, see MKOverlayLevel (page 47).

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

33

MKMapView Class Reference Instance Methods

Discussion Inserting an overlay at a specific level places that overlays visual representation in front of or behind other map content such as map labels and point-of-interest icons. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

insertOverlay:belowOverlay:
Inserts one overlay object below another.
- (void)insertOverlay:(id < MKOverlay >)overlay belowOverlay:(id < MKOverlay >)sibling

Parameters
overlay

The overlay object to insert.


sibling

An existing object in the overlays (page 15) array. This object must exist in the array and must not be nil. Discussion This method inserts the overlay into the MKOverlayLevelAboveLabels (page 48) level and positions it relative to the specified sibling. When displayed, this leads to the overlays contents being displayed beneath that of its sibling. If sibling is not in the same map level, this method appends the overlay to the end of the list of overlays at the indicated level. Availability Available in iOS 4.0 and later. See Also (page 33) insertOverlay:aboveOverlay: (page 32)
insertOverlay:atIndex:

Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

34

MKMapView Class Reference Instance Methods

mapRectThatFits:
Adjusts the aspect ratio of the specified map rectangle to ensure that it fits in the map views frame.
- (MKMapRect)mapRectThatFits:(MKMapRect)mapRect

Parameters
mapRect

The initial map rectangle whose width and height you want to adjust. Return Value A map rectangle that is still centered on the same point of the map but whose width and height are adjusted to fit in the map views frame. Discussion 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 views frame. Availability Available in iOS 4.0 and later. See Also
mapRectThatFits:edgePadding:

(page 35)

Declared in
MKMapView.h

mapRectThatFits:edgePadding:
Adjusts the aspect ratio of the specified map rectangle, incorporating the specified inset values.
- (MKMapRect)mapRectThatFits:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets

Parameters
mapRect

The initial map rectangle whose width and height you want to adjust.
insets

The distance (measured in screen points) by which to inset the returned rectangle from the actual boundaries of the map views frame.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

35

MKMapView Class Reference Instance Methods

Return Value A map rectangle that is still centered on the same point of the map but whose width and height are adjusted to fit in the map views frame minus the inset values. Availability Available in iOS 4.0 and later. See Also
mapRectThatFits:

(page 35)

Declared in
MKMapView.h

overlaysInLevel:
The overlay objects in the specified level of the map.
- (NSArray *)overlaysInLevel:(MKOverlayLevel)level

Parameters
level

The map level whose overlays you want. For a list of possible values for this parameter, see MKOverlayLevel (page 47). Return Value An array of objects conforming to the MKOverlay protocol that display in the specified map level. If there are no overlays at the specified level, this method returns an empty array. Discussion You can use this method to get all of the overlays assigned to a specific map level, which might be a subset of the complete set of overlay objects. For overlapping overlay objects, the order of objects in the array represents their visual order when displayed on the map, with objects in the beginning of the array located behind those at later indexes. Availability Available in iOS 7.0 and later. See Also
addOverlay:level: addOverlays:level:

(page 24) (page 26)

Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

36

MKMapView Class Reference Instance Methods

regionThatFits:
Adjusts the aspect ratio of the specified region to ensure that it fits in the map views frame.
- (MKCoordinateRegion)regionThatFits:(MKCoordinateRegion)region

Parameters
region

The initial region whose span you want to adjust. Return Value A region that is still centered on the same point of the map but whose span values are adjusted to fit in the map views frame. Discussion 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 views frame. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

removeAnnotation:
Removes the specified annotation object from the map view.
- (void)removeAnnotation:(id < MKAnnotation >)annotation

Parameters
annotation

The annotation object to remove. This object must conform to the MKAnnotation protocol. Discussion 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: (page 30) 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.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

37

MKMapView Class Reference Instance Methods

Availability Available in iOS 3.0 and later. See Also (page 38) addAnnotation: (page 22)
removeAnnotations:

Declared in
MKMapView.h

removeAnnotations:
Removes an array of annotation objects from the map view.
- (void)removeAnnotations:(NSArray *)annotations

Parameters
annotations

The array of annotations to remove. Objects in the array must conform to the MKAnnotation protocol. Discussion 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: (page 30) 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. Availability Available in iOS 3.0 and later. See Also (page 37) addAnnotations: (page 23)
removeAnnotation:

Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

38

MKMapView Class Reference Instance Methods

removeOverlay:
Removes a single overlay object from the map.
- (void)removeOverlay:(id < MKOverlay >)overlay

Parameters
overlay

The overlay object to remove. Discussion This method removes the overlay regardless of the level that it is in. Removing an overlay also removes its corresponding renderer, if one is in use. If the specified overlay is not currently associated with the map view, this method does nothing. Availability Available in iOS 4.0 and later. See Also (page 23) addOverlays: (page 25) removeOverlays: (page 39)
addOverlay:

Related Sample Code

Regions

Declared in
MKMapView.h

removeOverlays:
Removes one or more overlay objects from the map.
- (void)removeOverlays:(NSArray *)overlays

Parameters
overlays

An array of objects, each of which conforms to the MKOverlay protocol. Discussion This method removes the specified overlays regardless of which level each one is in. Removing an overlay also removes its corresponding renderer, if one is in use. If a given overlay object is not associated with the map view, it is ignored.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

39

MKMapView Class Reference Instance Methods

Availability Available in iOS 4.0 and later. See Also (page 23) addOverlays: (page 25) removeOverlay: (page 39)
addOverlay:

Declared in
MKMapView.h

rendererForOverlay:
Returns the renderer object used to draw the contents of the specified overlay object.
- (MKOverlayRenderer *)rendererForOverlay:(id < MKOverlay >)overlay

Parameters
overlay

The overlay object whose renderer you want. Return Value The renderer object in use for the specified overlay or nil if the overlay is not onscreen. Discussion This method returns the renderer object that your map delegate provided in its mapView:rendererForOverlay: method. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

selectAnnotation:animated:
Selects the specified annotation and displays a callout view for it.
- (void)selectAnnotation:(id < MKAnnotation >)annotation animated:(BOOL)animated

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

40

MKMapView Class Reference Instance Methods

Parameters
annotation

The annotation object to select.


animated

If YES, the callout view is animated into position. Discussion If the specified annotation is not onscreen, and therefore does not have an associated annotation view, this method has no effect. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

setCamera:animated:
Changes the camera used for determining the maps viewing parameters and optionally animates the change.
- (void)setCamera:(MKMapCamera *)camera animated:(BOOL)animated

Parameters
camera

The camera object containing the viewing angle information. This parameter must not be nil.
animated

Specify YES if you want the change in viewing angle to be animated or NO if you want the map to reflect the changes without animations. Availability Available in iOS 7.0 and later. See Also
@property camera

(page 13)

Declared in
MKMapView.h

setCenterCoordinate:animated:
Changes the center coordinate of the map and optionally animates the change.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

41

MKMapView Class Reference Instance Methods

- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

Parameters
coordinate

The new center coordinate for the map.


animated

Specify YES if you want the map view to scroll to the new location or NO if you want the map to display the new location immediately. Discussion Changing the center coordinate centers the map on the new coordinate without changing the current zoom level. It also updates the value in the region property to reflect the new center coordinate and the new span values needed to maintain the current zoom level. Availability Available in iOS 3.0 and later. See Also
@property centerCoordinate @property region

(page 14)

(page 16)

Declared in
MKMapView.h

setRegion:animated:
Changes the currently visible region and optionally animates the change.
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated

Parameters
region

The new region to display in the map view.


animated

Specify YES if you want the map view to animate the transition to the new region or NO if you want the map to center on the specified region immediately.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

42

MKMapView Class Reference Instance Methods

Discussion 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 (page 16) 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: (page 37) method to determine the region that will actually be set by the map.) Availability Available in iOS 3.0 and later. See Also
@property region

(page 16) (page 41)

setCenterCoordinate:animated:

Declared in
MKMapView.h

setUserTrackingMode:animated:
Sets the mode used to track the user location with optional animation.
- (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated

Parameters
mode

The mode used to track the user location. Possible values are described in MKUserTrackingMode (page 47).
animated

If YES, the change from the current mode to the new mode is animated; otherwise, it is not. This parameter affects only tracking mode changes. Changes to the user location or heading are always animated. Discussion Setting the tracking mode to MKUserTrackingModeFollow (page 47) or MKUserTrackingModeFollowWithHeading (page 47) causes the map view to center the map on that location and begin tracking the users location. If the map is zoomed out, the map view automatically zooms in on the users location, effectively changing the current visible region.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

43

MKMapView Class Reference Instance Methods

Availability Available in iOS 5.0 and later. See Also


@property userTrackingMode

(page 21)

mapView:didChangeUserTrackingMode:animated: mapView:didUpdateUserLocation: heading

Declared in
MKMapView.h

setVisibleMapRect:animated:
Changes the currently visible portion of the map and optionally animates the change.
- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate

Parameters
mapRect

The map rectangle to make visible in the map view.


animate

Specify YES if you want the map view to animate the transition to the new map rectangle or NO if you want the map to center on the specified rectangle immediately. Availability Available in iOS 4.0 and later. See Also
setVisibleMapRect:edgePadding:animated:

(page 44)

Declared in
MKMapView.h

setVisibleMapRect:edgePadding:animated:
Changes the currently visible portion of the map, allowing you to specify additional space around the edges.
- (void)setVisibleMapRect:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets

animated:(BOOL)animate

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

44

MKMapView Class Reference Instance Methods

Parameters
mapRect

The map rectangle to make visible in the map view.


insets

The amount of additional space (measured in screen points) to make visible around the specified rectangle.
animate

Specify YES if you want the map view to animate the transition to the new map rectangle or NO if you want the map to center on the specified rectangle immediately. Availability Available in iOS 4.0 and later. See Also
setVisibleMapRect:animated:

(page 44)

Declared in
MKMapView.h

showAnnotations:animated:
Sets the visible region so that the map displays the specified annotations.
- (void)showAnnotations:(NSArray *)annotations animated:(BOOL)animated

Parameters
annotations

The annotations that you want to be visible in the map.


animated YES if you want the map region change to be animated, or NO if you want the map to display the new

region immediately without animations. Discussion Calling this method updates the value in the region property and potentially other properties to reflect the new map region. Availability Available in iOS 7.0 and later. Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

45

MKMapView Class Reference Constants

viewForAnnotation:
Returns the annotation view associated with the specified annotation object, if any.
- (MKAnnotationView *)viewForAnnotation:(id < MKAnnotation >)annotation

Parameters
annotation

The annotation object whose view you want. Return Value The annotation view or nil if the view has not yet been created. This method may also return nil if the annotation is not in the visible map region and therefore does not have an associated annotation view. Availability Available in iOS 3.0 and later. Declared in
MKMapView.h

Constants
MKMapType
The type of map to display.

typedef enum : NSUInteger{ MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid } MKMapType;

Constants
MKMapTypeStandard

Displays a street map that shows the position of all roads and some road names. Available in iOS 3.0 and later. Declared in MKTypes.h.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

46

MKMapView Class Reference Constants

MKMapTypeSatellite

Displays satellite imagery of the area. Available in iOS 3.0 and later. Declared in MKTypes.h.
MKMapTypeHybrid

Displays a satellite image of the area with road and road name information layered on top. Available in iOS 3.0 and later. Declared in MKTypes.h.

MKUserTrackingMode
The mode used to track the user location on the map.

typedef enum : NSInteger { MKUserTrackingModeNone = 0, MKUserTrackingModeFollow, MKUserTrackingModeFollowWithHeading, } MKUserTrackingMode;

Constants
MKUserTrackingModeNone

The map does not follow the user location. Available in iOS 5.0 and later. Declared in MKMapView.h.
MKUserTrackingModeFollow

The map follows the user location. Available in iOS 5.0 and later. Declared in MKMapView.h.
MKUserTrackingModeFollowWithHeading

The map follows the user location and rotates when the heading changes. Available in iOS 5.0 and later. Declared in MKMapView.h.

MKOverlayLevel
Constants indicating the position of overlays relative to other content.

typedef enum : NSInteger {

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

47

MKMapView Class Reference Constants

MKOverlayLevelAboveRoads = 0, MKOverlayLevelAboveLabels } MKOverlayLevel;

Constants
MKOverlayLevelAboveRoads

Place the overlay above roadways but below map labels, shields, or point-of-interest icons. Available in iOS 7.0 and later. Declared in MKMapView.h.
MKOverlayLevelAboveLabels

Place the overlay above map labels, shields, or point-of-interest icons but below annotations and 3D projections of buildings. Available in iOS 7.0 and later. Declared in MKMapView.h.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

48

Deprecated MKMapView Methods

A method identified as deprecated has been superseded and may become unsupported in the future.

Deprecated in iOS 7.0


viewForOverlay:
Returns the view associated with the overlay object if any. (Deprecated in iOS 7.0. Use the rendererForOverlay: (page 40) method instead.)
- (MKOverlayView *)viewForOverlay:(id < MKOverlay >)overlay

Parameters
overlay

The overlay object whose view you want. Return Value The view associated with the overlay object or nil if the overlay is not onscreen. Availability Available in iOS 4.0 and later. Deprecated in iOS 7.0. Declared in
MKMapView.h

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

49

Document Revision History

This table describes the changes to MKMapView Class Reference .

Date 2013-09-18

Notes Added new methods for managing overlays. Updated description of annotationsInMapRect: (page 26).

2011-10-12 2010-11-15 2010-05-11 2009-07-27 2009-05-12

Updated for iOS 5.0. Documented the annotationsInMapRect: method, which is new in iOS 4.2. Added symbols introduced in iOS 4.0. Updated the description of the annotations property. New document that describes the class for managing an embeddable map interface.

2013-09-18 | Copyright 2013 Apple Inc. All Rights Reserved.

50

Apple Inc. Copyright 2013 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, Cocoa, and Cocoa Touch are trademarks of Apple Inc., registered in the U.S. and other countries. iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.

Anda mungkin juga menyukai