大頭針固定在屏幕上
///是否固定在屏幕一點, 注意,拖動或者手動改變經(jīng)緯度俯萎,都會導(dǎo)致設(shè)置失效
@property (nonatomic, assign, getter = isLockedToScreen) BOOL lockedToScreen;
///固定屏幕點的坐標(biāo)
@property (nonatomic, assign) CGPoint lockedScreenPoint;
//MAPointAnnotation ?*annotation;//系統(tǒng)大頭針傲宜,繼承至MAAnnotation
//MAPinAnnotationView ?//系統(tǒng)預(yù)定好的一個annotationView提供類似大頭針的效果
MAAnnotationView 標(biāo)注View 可以通過繼承它來自定義大頭針(標(biāo)注)
///提供類似大頭針效果的annotation view
@interface MAPinAnnotationView : MAAnnotationView
?self.annotation.lockedScreenPoint = CGPointMake(self.mapView.centerX, self.mapView.centerY);
/**
?* @brief 設(shè)置當(dāng)前地圖的中心點,改變該值時夫啊,地圖的比例尺級別不會發(fā)生變化
?* @paramcoordinate要設(shè)置的中心點
?* @paramanimated是否動畫設(shè)置
?*/
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinateanimated:(BOOL)animated;
?[self.mapView setCenterCoordinate:self.coordinate animated:YES];
? self.annotation.lockedToScreen = YES;
被固定在地圖中央的大頭針蛋哭,在移動地圖的時候,大頭針跳起涮母,移動結(jié)束后落下
實現(xiàn)過程:用了兩張圖片 ?根據(jù)情況改變自定義大頭針的圖片
/**
?* @brief 地圖區(qū)域改變過程中會調(diào)用此接口 since 4.6.0
?* @parammapView地圖View
?*/
- (void)mapViewRegionChanged:(MAMapView *)mapView;
/**
?* @brief 地圖區(qū)域即將改變時會調(diào)用此接口
?* @parammapView地圖View
?* @paramanimated是否動畫
?*/
- (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
在地圖區(qū)域?qū)⒁淖冏恢海淖冞^程中兩個代理方法里面用跳起的圖片
/**
?* @brief 地圖區(qū)域改變完成后會調(diào)用此接口
?* @parammapView地圖View
?* @paramanimated是否動畫
?*/
- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
在地圖區(qū)域改變完成后用落下的圖片
大頭針氣泡是自定義UIView
允許顯示showCallOut 躁愿,那就通過addSubView的方式展示在大頭針上面(self)
? [self addSubview:self.qiPaoView];
?? ?[self.qiPaoView mas_makeConstraints:^(MASConstraintMaker *make) {
? ? ? ? make.bottom.mas_equalTo(self.mas_top);
? ? ? ? make.centerX.mas_equalTo(self);
? ? }];
MAUserLocationRepresentation:地圖上當(dāng)前用戶位置顯示控制
向地圖上添加大頭針
[mapView addAnnotation:annotation];
地圖上展示的是MAAnnotationView、MAPinAnnotationView沪蓬、自定義annotationView
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
?if([annotationisKindOfClass:[MAUserLocation class]]) {
//可以展示自定義annotationView
/* ? ? ?static
? ? ? ? NSString*userLocationStyleReuseIndetifier =@"userLocationStyleReuseIndetifier";
? ? ? ? DEACustomAnnotationView*annotationView = (DEACustomAnnotationView*)[mapViewdequeueReusableAnnotationViewWithIdentifier:userLocationStyleReuseIndetifier];
? ? ? ? if(annotationView ==nil) {
? ? ? ? ? ? annotationView = [[DEACustomAnnotationViewalloc]initWithAnnotation:annotation? reuseIdentifier:userLocationStyleReuseIndetifier];
? ? ? ? }*/
//也可以自定義精度圈
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc]init];
r.showsAccuracyRing = NO;///精度圈是否顯示彤钟,默認(rèn)YES
r.showsHeadingIndicator = NO;///是否顯示方向指示(MAUserTrackingModeFollowWithHeading模式開啟)。默認(rèn)為YES
r.fillColor = [UIColor redColor];///精度圈 填充顏色, 默認(rèn) kAccuracyCircleDefaultColor
r.strokeColor = [UIColor blueColor];///精度圈 邊線顏色, 默認(rèn) kAccuracyCircleDefaultColor
r.lineWidth = 2;///精度圈 邊線寬度跷叉,默認(rèn)0
r.enablePulseAnnimation = NO;///內(nèi)部藍(lán)色圓點是否使用律動效果, 默認(rèn)YES
r.locationDotBgColor = [UIColor greenColor];///定位點背景色逸雹,不設(shè)置默認(rèn)白色
r.locationDotFillColor = [UIColor grayColor];///定位點藍(lán)色圓點顏色,不設(shè)置默認(rèn)藍(lán)色
r.image = [UIImage imageNamed:@"你的圖片"]; ///定位圖標(biāo), 與藍(lán)色原點互斥
[self.mapView updateUserLocationRepresentation:r];
//若什么都不展示
return nil;
}
地圖上展示不同數(shù)據(jù)的annotationview
可以繼承MAPointAnnotation 實現(xiàn)自定義大頭針加一個屬性 index 用來區(qū)分是哪個大頭針
在view上展示內(nèi)容的時候云挟,根據(jù)index取出相應(yīng)的數(shù)據(jù)
?if([annotation isKindOfClass:[HHPointAnnotation class]])
? ? {
? ? ? ? static NSString*customReuseIndetifier =@"customReuseIndetifier";
? ? ? ? HHPointAnnotation*ano = annotation;
? ? ? ? CustomAnnotationView*annotationView = (CustomAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndetifier];
? ? ? ? if(annotationView ==nil)
? ? ? ? {
? ? ? ? ? ? annotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotationreuseIdentifier:customReuseIndetifier];
? ? ? ? ? ? annotationView.canShowCallout=NO;
? ? ? ? ? ? annotationView.draggable=YES;
? ? ? ? }
? ? ? ? AnnotationModel *model = self.dataArray[ano.index];
? ? ? ? annotationView.image= [UIImage imageNamed:model.imageName];
? ? ? ?return annotationView;
}