MKMapView控件對象的屬性和方法
屬性
1.設(shè)置地圖類型<pre>@property (nonatomic) MKMapType mapType;</pre>MKMapType枚舉
MKMapTypeStandard 標(biāo)準(zhǔn)式的行政地圖(顯示城市/街道)
MKMapTypeSatellite 標(biāo)準(zhǔn)的衛(wèi)星地圖
MKMapTypeHybrid 混合地圖(在衛(wèi)星圖上顯示街道等名稱)
MKMapTypeSatelliteFlyover (iOS9)
MKMapTypeHybridFlyover (iOS9)
2.設(shè)置范圍
<pre>@property (nonatomic) MKCoordinateRegion region;</pre>MKCoordinateRegion
CLLocationCoordinate2D 地圖中心的經(jīng)緯度
latitude 緯度 北緯為正,南緯為負(fù)
longitude 經(jīng)度 東經(jīng)為正,西經(jīng)為負(fù)
MKCoordinateSpan 地圖顯示的經(jīng)緯度范圍
latitudeDelta 緯度范圍 (0-180)
longitudeDelta 經(jīng)度范圍 (0-360)
ps:MKCoordinateSpan的顯示范圍是取決于大的一邊的。
3.設(shè)置地圖的中心坐標(biāo)<pre>@property (nonatomic) CLLocationCoordinate2D centerCoordinate;</pre>4.設(shè)置縮放(默認(rèn)是允許)<pre>
@property (nonatomic, getter=isZoomEnabled) BOOL zoomEnabled;</pre>5.設(shè)置滑動(dòng)(默認(rèn)是允許)<pre>
@property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;</pre>6.設(shè)置旋轉(zhuǎn)(默認(rèn)是允許)(iOS7)<pre>
@property (nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;</pre>7.設(shè)置3D效果(iOS7)<pre>
@property (nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;</pre>8.設(shè)置顯示用戶位置<pre>
@property (nonatomic) BOOL showsUserLocation;</pre>9.設(shè)置更新用戶位置的模式(當(dāng)顯示用戶位置設(shè)置為YES,這個(gè)方法也設(shè)置了后,地圖框架為我們直接集成了定位,地圖上就會(huì)顯示我們的位置)<pre>
@property (nonatomic) MKUserTrackingMode userTrackingMode;</pre>MKUserTrackingMode枚舉
MKUserTrackingModeFollow 跟蹤用戶位置
MKUserTrackingModeNone 不跟蹤用戶位置
MKUserTrackingModeFollowWithHeading 當(dāng)方向改變時(shí)跟蹤用戶位置
10.設(shè)置顯示興趣點(diǎn)(例如學(xué)校/醫(yī)院等)(iOS7)<pre>@property (nonatomic) BOOL showsPointsOfInterest;</pre>只在地圖類型為MKMapTypeStandard和MKMapTypeHybrid時(shí)起作用。
11.設(shè)置顯示建筑物輪廓(iOS7)<pre>@property (nonatomic) BOOL showsBuildings;</pre>只在地圖類型為MKMapTypeStandard時(shí)起作用。
12.設(shè)置顯示交通(iOS9)<pre>@property (nonatomic) BOOL showsTraffic NS_AVAILABLE(10_11, 9_0); // Affects MKMapTypeStandard and MKMapTypeHybrid</pre>13.設(shè)置顯示指南針(iOS9)<pre>
@property (nonatomic) BOOL showsCompass NS_AVAILABLE(10_9, 9_0) __TVOS_PROHIBITED;</pre>14.設(shè)置顯示比例尺(iOS9)<pre>
@property (nonatomic) BOOL showsScale NS_AVAILABLE(10_10, 9_0);</pre>方法
<pre>
- (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 <MKAnnotation>)annotation;
- (void)addAnnotations:(NSArray<id<MKAnnotation>> *)annotations;
- (nullable MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation;
- (nullable MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
- (void)selectAnnotation:(id <MKAnnotation>)annotation animated:(BOOL)animated;
- (void)deselectAnnotation:(nullable id <MKAnnotation>)annotation animated:(BOOL)animated;
- (void)showAnnotations:(NSArray<id<MKAnnotation>> *)annotations animated:(BOOL)animated NS_AVAILABLE(10_9, 7_0);
- (void)removeAnnotation:(id <MKAnnotation>)annotation;
- (void)removeAnnotations:(NSArray<id<MKAnnotation>> *)annotations;
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view;
//將經(jīng)緯度轉(zhuǎn)換為試圖上的坐標(biāo) - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view;
//將試圖上的坐標(biāo)轉(zhuǎn)化為經(jīng)緯度 - (CGRect)convertRegion:(MKCoordinateRegion)region toRectToView:(nullable UIView *)view;
//將地理顯示的區(qū)域轉(zhuǎn)化為試圖上的坐標(biāo)區(qū)域 - (MKCoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(nullable UIView *)view;
//將試圖上的坐標(biāo)區(qū)域轉(zhuǎn)化為地理區(qū)域 - (void)removeOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 4_0);</pre>地圖上增加覆蓋物(OverlaysAPI)
<pre>- (void)removeOverlays:(NSArray<id<MKOverlay>> *)overlays NS_AVAILABLE(10_9, 4_0); - (void)insertOverlay:(id <MKOverlay>)overlay atIndex:(NSUInteger)index level:(MKOverlayLevel)level NS_AVAILABLE(10_9, 7_0);
- (void)insertOverlay:(id <MKOverlay>)overlay aboveOverlay:(id <MKOverlay>)sibling NS_AVAILABLE(10_9, 4_0);
- (void)insertOverlay:(id <MKOverlay>)overlay belowOverlay:(id <MKOverlay>)sibling NS_AVAILABLE(10_9, 4_0);
- (void)exchangeOverlay:(id <MKOverlay>)overlay1 withOverlay:(id <MKOverlay>)overlay2 NS_AVAILABLE(10_9, 7_0);
- (nullable MKOverlayRenderer *)rendererForOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 7_0);
- (void)addOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 4_0);
- (void)addOverlays:(NSArray<id<MKOverlay>> *)overlays NS_AVAILABLE(10_9, 4_0);
- (void)insertOverlay:(id <MKOverlay>)overlay atIndex:(NSUInteger)index NS_AVAILABLE(10_9, 4_0);
- (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2 NS_AVAILABLE(10_9, 4_0);</pre>代理方法(MKMapViewDelegate)
<pre>
//地圖將要加載時(shí)調(diào)用的方法 - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
//地圖加載完成時(shí)執(zhí)行的方法 - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
//地圖加載失敗時(shí)執(zhí)行的方法 - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
//渲染標(biāo)注試圖時(shí)調(diào)用的方法,可以通過這個(gè)方法自定義標(biāo)注試圖 - (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
//標(biāo)注添加完成后調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray<MKAnnotationView *> *)views;
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control __TVOS_PROHIBITED;
//選中標(biāo)注時(shí)調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
//取消選中標(biāo)注時(shí)調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view NS_AVAILABLE(10_9, 4_0);
//地圖顯示區(qū)域?qū)⒁淖?/li> - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
//地圖顯示區(qū)域已經(jīng)改變 - (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);
//將要開始定位用戶位置時(shí)調(diào)用的方法 - (void)mapViewWillStartLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
//停止定位用戶位置時(shí)調(diào)用的方法 - (void)mapViewDidStopLocatingUser:(MKMapView *)mapView NS_AVAILABLE(10_9, 4_0);
//更新用戶位置時(shí)調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation NS_AVAILABLE(10_9, 4_0);
//更新用戶位置失敗時(shí)調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error NS_AVAILABLE(10_9, 4_0);
//標(biāo)注拖動(dòng)狀態(tài)改變調(diào)用的方法 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState NS_AVAILABLE(10_9, 4_0) __TVOS_PROHIBITED;
//定位用戶位置模式改變時(shí)調(diào)用的方法 - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated NS_AVAILABLE(NA, 5_0);
//地圖添加覆蓋物層數(shù)據(jù)模型時(shí),回調(diào)的代理方法。通過此方法,返回對應(yīng)的渲染圖層 - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay NS_AVAILABLE(10_9, 7_0);
- (void)mapView:(MKMapView *)mapView didAddOverlayRenderers:(NSArray<MKOverlayRenderer *> *)renderers NS_AVAILABLE(10_9, 7_0);
//渲染覆蓋物試圖時(shí)調(diào)用的方法,可以自定義覆蓋物試圖 - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
//添加完成覆蓋物數(shù)組之行的方法 - (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews NS_DEPRECATED_IOS(4_0, 7_0) __TVOS_PROHIBITED;
</pre>