iOS 高德地圖修改定位默認(rèn)小藍(lán)點(diǎn)樣式

需求:顯示目標(biāo)點(diǎn)以及自己所在位置赎瞎,且有方向跟隨。
先來張效果圖:


CB1C3DEA-5126-47E4-BBE6-BD563C17DEA8.jpeg

1淑掌、初始化地圖

 -(MAMapView*)mapView{
      if(!_mapView) {
          self.mapView = [ZWMemoryCache.cache MAMapView];

          _mapView.frame=CGRectMake(0,kSafeTop,KW,KH-kSafeTop);

          _mapView.delegate=self;

          //1.1顶捷、顯示用戶位置(重點(diǎn))

          _mapView.showsUserLocation = YES;

          //地圖跟著位置移動

          _mapView.userTrackingMode = MAUserTrackingModeFollow;

          //設(shè)置定位精度

          _mapView.desiredAccuracy = kCLLocationAccuracyBest;

          //設(shè)置定位距離

          _mapView.distanceFilter = 5.0f;



          _mapView.mapType = MKMapTypeStandard;

          //1.2、新增點(diǎn)A

           CLLocationCoordinate2D location = CLLocationCoordinate2DMake([_pointMod.position.coordinates[1] doubleValue], [_pointMod.position.coordinates[0] doubleValue]);//緯度翰蠢,經(jīng)度

          MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];

          pointAnnotation.coordinate= location;

          pointAnnotation.title=_pointMod.name;

          pointAnnotation.subtitle= [NSStringstringWithFormat:@"%@",_pointMod.position.coordinates];

          [_mapViewaddAnnotation:pointAnnotation];       

           //將目標(biāo)經(jīng)緯度設(shè)置為地圖中心店

          self.mapView.centerCoordinate= location;
      }
      return _mapView;
  }

2项乒、在代理方法中修改定位點(diǎn)的圖標(biāo),以及去除默認(rèn)的淡藍(lán)色圈

- (MAAnnotationView*)mapView:(MAMapView*)mapView viewForAnnotation:(id)annotation
{
    //系統(tǒng)默認(rèn)的當(dāng)前位置點(diǎn)

    if ([annotation isKindOfClass:[MAUserLocation class]]) {

        staticNSString*userLocationStyleReuseIndetifier =@"userLocationStyleReuseIndetifier";

        MAAnnotationView*annotationView = [mapViewdequeueReusableAnnotationViewWithIdentifier:userLocationStyleReuseIndetifier];

        if(annotationView ==nil) {

            annotationView = [[MAPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:userLocationStyleReuseIndetifier];

        }

        //2.1梁沧、設(shè)置為帶箭頭的圖標(biāo)

        annotationView.image= [UIImageimageNamed:@"userPosition"];

        self.userLocationAnnotationView= annotationView;



        //2.2板丽、去掉高德地圖淡藍(lán)色精度圈

        MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];

        r.showsAccuracyRing = false;///精度圈是否顯示,默認(rèn)YES

        [mapViewupdateUserLocationRepresentation:r];



        returnannotationView;

    }

    //新增的點(diǎn)A

    else if ([annotation isKindOfClass:[MAPointAnnotation class]]) {

        staticNSString*pointReuseIndentifier =@"annotationReuseIndetifier";

        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];

        if(annotationView ==nil)

        {

            annotationView = [[MAPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:pointReuseIndentifier];

        }

        annotationView.canShowCallout=YES;      //設(shè)置氣泡可以彈出趁尼,默認(rèn)為NO

        annotationView.animatesDrop=YES;        //設(shè)置標(biāo)注動畫顯示埃碱,默認(rèn)為NO

//        annotationView.draggable = YES;        //設(shè)置標(biāo)注可以拖動,默認(rèn)為NO

//        annotationView.pinColor = MAPinAnnotationColorPurple;

        //2.3酥泞、設(shè)置自定義點(diǎn)樣式

        annotationView.image= [UIImageimageNamed:@"searchPosition"];



        returnannotationView;

    }
    return nil;
}

3砚殿、設(shè)置箭頭指示方位

 - (void)mapView:(MAMapView*)mapView didUpdateUserLocation:(MAUserLocation*)userLocation updatingLocation:(BOOL)updatingLocation
{
    //設(shè)置箭頭指示方位

    if(!updatingLocation &&self.userLocationAnnotationView!=nil) {

        [UIView animateWithDuration:0.1 animations:^{

            doubledegree = userLocation.heading.trueHeading-self.mapView.rotationDegree;

            self.userLocationAnnotationView.transform = CGAffineTransformMakeRotation(degree * M_PI / 180.f );

        }];
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市芝囤,隨后出現(xiàn)的幾起案子似炎,更是在濱河造成了極大的恐慌辛萍,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,888評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件羡藐,死亡現(xiàn)場離奇詭異贩毕,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)仆嗦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評論 3 399
  • 文/潘曉璐 我一進(jìn)店門辉阶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人瘩扼,你說我怎么就攤上這事谆甜。” “怎么了集绰?”我有些...
    開封第一講書人閱讀 168,386評論 0 360
  • 文/不壞的土叔 我叫張陵规辱,是天一觀的道長。 經(jīng)常有香客問我栽燕,道長罕袋,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,726評論 1 297
  • 正文 為了忘掉前任碍岔,我火速辦了婚禮炫贤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘付秕。我一直安慰自己兰珍,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,729評論 6 397
  • 文/花漫 我一把揭開白布询吴。 她就那樣靜靜地躺著掠河,像睡著了一般。 火紅的嫁衣襯著肌膚如雪猛计。 梳的紋絲不亂的頭發(fā)上唠摹,一...
    開封第一講書人閱讀 52,337評論 1 310
  • 那天,我揣著相機(jī)與錄音奉瘤,去河邊找鬼勾拉。 笑死,一個(gè)胖子當(dāng)著我的面吹牛盗温,可吹牛的內(nèi)容都是我干的藕赞。 我是一名探鬼主播,決...
    沈念sama閱讀 40,902評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼卖局,長吁一口氣:“原來是場噩夢啊……” “哼斧蜕!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起砚偶,我...
    開封第一講書人閱讀 39,807評論 0 276
  • 序言:老撾萬榮一對情侶失蹤批销,失蹤者是張志新(化名)和其女友劉穎洒闸,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體均芽,經(jīng)...
    沈念sama閱讀 46,349評論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡丘逸,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,439評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了掀宋。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片深纲。...
    茶點(diǎn)故事閱讀 40,567評論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖布朦,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情昼窗,我是刑警寧澤是趴,帶...
    沈念sama閱讀 36,242評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站澄惊,受9級特大地震影響唆途,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜掸驱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,933評論 3 334
  • 文/蒙蒙 一肛搬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧毕贼,春花似錦温赔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至待秃,卻和暖如春拜秧,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背章郁。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評論 1 272
  • 我被黑心中介騙來泰國打工枉氮, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人暖庄。 一個(gè)月前我還...
    沈念sama閱讀 48,995評論 3 377
  • 正文 我出身青樓聊替,卻偏偏與公主長得像,于是被迫代替她去往敵國和親培廓。 傳聞我的和親對象是個(gè)殘疾皇子佃牛,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,585評論 2 359

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