MKMapView控件对象的属性和方法
属性
1.设置地图类型
@property (nonatomic) MKMapType mapType;MKMapType枚举
MKMapTypeStandard 标准式的行政地图(显示城市/街道)
MKMapTypeSatellite 标准的卫星地图
MKMapTypeHybrid 混合地图(在卫星图上显示街道等名称)
MKMapTypeSatelliteFlyover (iOS9)
MKMapTypeHybridFlyover (iOS9)
2.设置范围
@property (nonatomic) MKCoordinateRegion region;MKCoordinateRegion
CLLocationCoordinate2D 地图中心的经纬度
latitude 纬度 北纬为正,南纬为负
longitude 经度 东经为正,西经为负
MKCoordinateSpan 地图显示的经纬度范围
latitudeDelta 纬度范围 (0-180)
longitudeDelta 经度范围 (0-360)
ps:MKCoordinateSpan的显示范围是取决于大的一边的。
3.设置地图的中心坐标
@property (nonatomic) CLLocationCoordinate2D centerCoordinate;4.设置缩放(默认是允许)
5.设置滑动(默认是允许)
@property (nonatomic, getter=isZoomEnabled) BOOL zoomEnabled;
6.设置旋转(默认是允许)(iOS7)
@property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
7.设置3D效果(iOS7)
@property (nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;
8.设置显示用户位置
@property (nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;
9.设置更新用户位置的模式(当显示用户位置设置为YES,这个方法也设置了后,地图框架为我们直接集成了定位,地图上就会显示我们的位置)
@property (nonatomic) BOOL showsUserLocation;
MKUserTrackingMode枚举
@property (nonatomic) MKUserTrackingMode userTrackingMode;
MKUserTrackingModeFollow 跟踪用户位置
MKUserTrackingModeNone 不跟踪用户位置
MKUserTrackingModeFollowWithHeading 当方向改变时跟踪用户位置
10.设置显示兴趣点(例如学校/医院等)(iOS7)
@property (nonatomic) BOOL showsPointsOfInterest;只在地图类型为MKMapTypeStandard和MKMapTypeHybrid时起作用。
11.设置显示建筑物轮廓(iOS7)
@property (nonatomic) BOOL showsBuildings;只在地图类型为MKMapTypeStandard时起作用。
12.设置显示交通(iOS9)
@property (nonatomic) BOOL showsTraffic NS_AVAILABLE(10_11, 9_0); // Affects MKMapTypeStandard and MKMapTypeHybrid13.设置显示指南针(iOS9)
14.设置显示比例尺(iOS9)
@property (nonatomic) BOOL showsCompass NS_AVAILABLE(10_9, 9_0) __TVOS_PROHIBITED;
方法
@property (nonatomic) BOOL showsScale NS_AVAILABLE(10_10, 9_0);
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
- (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated NS_AVAILABLE(NA, 5_0);
- (void)addAnnotation:(id
)annotation; - (void)addAnnotations:(NSArray
> *)annotations; - (nullable MKAnnotationView *)viewForAnnotation:(id
)annotation; - (nullable MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
- (void)selectAnnotation:(id
)annotation animated:(BOOL)animated; - (void)deselectAnnotation:(nullable id
)annotation animated:(BOOL)animated; - (void)showAnnotations:(NSArray
> *)annotations animated:(BOOL)animated NS_AVAILABLE(10_9, 7_0); - (void)removeAnnotation:(id
)annotation; - (void)removeAnnotations:(NSArray
> *)annotations; - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view;
//将经纬度转换为试图上的坐标 - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view;
//将试图上的坐标转化为经纬度 - (CGRect)convertRegion:(MKCoordinateRegion)region toRectToView:(nullable UIView *)view;
//将地理显示的区域转化为试图上的坐标区域 - (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(nullable UIView *)view;
//将试图上的坐标区域转化为地理区域 - (void)removeOverlay:(id
)overlay NS_AVAILABLE(10_9, 4_0);地图上增加覆盖物(OverlaysAPI)
- (void)removeOverlays:(NSArray
> *)overlays NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id
)overlay atIndex:(NSUInteger)index level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0); - (void)insertOverlay:(id
)overlay aboveOverlay:(id )sibling NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id
)overlay belowOverlay:(id )sibling NS_AVAILABLE(10_9, 4_0); - (void)exchangeOverlay:(id
)overlay1 withOverlay:(id )overlay2 NS_AVAILABLE(10_9, 7_0); - (nullable MKOverlayRenderer *)rendererForOverlay:(id
)overlay NS_AVAILABLE(10_9, 7_0); - (void)addOverlay:(id
)overlay NS_AVAILABLE(10_9, 4_0); - (void)addOverlays:(NSArray
> *)overlays NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id
)overlay atIndex:(NSUInteger)index NS_AVAILABLE(10_9, 4_0); - (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2 NS_AVAILABLE(10_9, 4_0);代理方法(MKMapViewDelegate)
//地图将要加载时调用的方法 - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
//地图加载完成时执行的方法 - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
//地图加载失败时执行的方法 - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
//渲染标注试图时调用的方法,可以通过这个方法自定义标注试图 - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id
)annotation;
//标注添加完成后调用的方法 - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray
*)views; - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control __TVOS_PROHIBITED;
//选中标注时调用的方法 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
//取消选中标注时调用的方法 - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
//地图显示区域将要改变 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
//地图显示区域已经改变 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
- (void)mapViewWillStartRenderingMap:(MKMapView *)mapView NS_AVAILABLE(10_9, 7_0);
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered NS_AVAILABLE(10_9, 7_0);
//将要开始定位用户位置时调用的方法 - (void)mapViewWillStartLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
//停止定位用户位置时调用的方法 - (void)mapViewDidStopLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
//更新用户位置时调用的方法 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0);
//更新用户位置失败时调用的方法 - (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error NS_AVAILABLE(10_9, 4_0);
//标注拖动状态改变调用的方法 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState NS_AVAILABLE(10_9, 4_0) __TVOS_PROHIBITED;
//定位用户位置模式改变时调用的方法 - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated NS_AVAILABLE(NA, 5_0);
//地图添加覆盖物层数据模型时,回调的代理方法。通过此方法,返回对应的渲染图层 - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id
)overlay NS_AVAILABLE(10_9, 7_0); - (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray
*)renderers NS_AVAILABLE(10_9, 7_0);
//渲染覆盖物试图时调用的方法,可以自定义覆盖物试图 - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id
)overlay NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
//添加完成覆盖物数组之行的方法 - (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;