iOS高德地圖大頭針的運用

大頭針固定在屏幕上

///是否固定在屏幕一點, 注意,拖動或者手動改變經(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;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末梆砸,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子园欣,更是在濱河造成了極大的恐慌帖世,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件沸枯,死亡現(xiàn)場離奇詭異日矫,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)绑榴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進(jìn)店門哪轿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人翔怎,你說我怎么就攤上這事窃诉。” “怎么了赤套?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵褐奴,是天一觀的道長。 經(jīng)常有香客問我于毙,道長敦冬,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任唯沮,我火速辦了婚禮脖旱,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘介蛉。我一直安慰自己萌庆,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布币旧。 她就那樣靜靜地躺著践险,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上巍虫,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天彭则,我揣著相機(jī)與錄音,去河邊找鬼占遥。 笑死俯抖,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的瓦胎。 我是一名探鬼主播芬萍,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼搔啊!你這毒婦竟也來了柬祠?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤负芋,失蹤者是張志新(化名)和其女友劉穎漫蛔,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體示罗,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡惩猫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年芝硬,在試婚紗的時候發(fā)現(xiàn)自己被綠了蚜点。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡拌阴,死狀恐怖绍绘,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情迟赃,我是刑警寧澤陪拘,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站纤壁,受9級特大地震影響左刽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜酌媒,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一欠痴、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧秒咨,春花似錦喇辽、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春抽米,著一層夾襖步出監(jiān)牢的瞬間特占,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工缨硝, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留摩钙,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓查辩,卻偏偏與公主長得像胖笛,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子宜岛,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容