高德地圖

#pragma mark - 創(chuàng)建地圖

-(void)createMapView
{
    _mapView = [[MAMapView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_mapView];
    //設(shè)置代理
    _mapView.delegate = self;
    /*高德地圖涉及到的一些屬性*/
    //1.設(shè)置是否顯示底層的建筑名稱標注
    _mapView.showsLabels = YES;
    //2.設(shè)置地圖的類型,分為衛(wèi)星地圖黄橘,標準地圖和夜景地圖
    _mapView.mapType = MAMapTypeStandard;
    //3.設(shè)置是否顯示交通狀況
    _mapView.showTraffic = YES;
    //4.設(shè)置顯示本人的位置,結(jié)合定位功能使用
    _mapView.showsUserLocation = YES;
    //5.設(shè)置地圖logo牛哺,默認字樣是“高德地圖”,用logoCenter來設(shè)置logo的位置
    _mapView.logoCenter = CGPointMake(self.view.frame.size.width - 100, self.view.frame.size.height - 50);
    //6.設(shè)置指南針compass,默認是開啟狀態(tài),大小是定值并闲,顯示在地圖的右上角
    _mapView.showsCompass = YES;
    _mapView.compassOrigin = self.view.center;
   //7.設(shè)置比例尺scale,默認顯示在地圖的左上角
   _mapView.showsScale = YES;
   _mapView.scaleOrigin = CGPointMake(100, 100);
   //8.設(shè)置地圖手勢
   _mapView.zoomEnabled = YES;//開啟地圖手勢
   //[_mapView setZoomLevel:15 animated:YES];
   //9.設(shè)置是否開啟滑動手勢
   _mapView.scrollEnabled = YES;
   //10.設(shè)置是否開啟旋轉(zhuǎn)手勢
   _mapView.rotateEnabled = YES;
   //11.設(shè)置是否開啟傾斜手勢
   _mapView.rotateCameraEnabled = YES;
}

#pragma mark - 在地圖上添加大頭針標注

-(void)addAnnotation
{
    MAPointAnnotation * pointAnnotation = [[MAPointAnnotation alloc]init];
    //設(shè)置大頭針需要標記的位置
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);
    //設(shè)置標題
    pointAnnotation.title = @"方恒國際";
    //設(shè)置副標題
    pointAnnotation.subtitle = @"這是我家";
    [_mapView addAnnotation:pointAnnotation];
}

#pragma mark - 設(shè)置大頭針的代理方法

-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
   /*
    //1.用系統(tǒng)的大頭針樣式
    //大頭針也涉及到復(fù)用叹哭,它的復(fù)用跟UITableViewCell的復(fù)用機制一樣
    //面向?qū)ο笳Z言的特性:封裝忍宋,繼承,多態(tài)(父類的指針可以指向子類的對象)
    MAPinAnnotationView * pinAnotationView = (MAPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"mapView"];
    //判斷復(fù)用池中是否有可用的對象风罩,如果沒有則創(chuàng)建
    if (!pinAnotationView) {
        pinAnotationView = [[MAPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"mapView"];
    }
    //設(shè)置氣泡可以顯示
    pinAnotationView.canShowCallout = YES;
    //設(shè)置大頭針降落的動畫
    pinAnotationView.animatesDrop = YES;
    //設(shè)置大頭針的顏色
    pinAnotationView.pinColor = MAPinAnnotationColorPurple;
    //設(shè)置大頭針是否可以拖拽
    pinAnotationView.draggable = YES;
    return pinAnotationView;
 */


     //2.使用自定義的大頭針樣式
     MAAnnotationView * annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"mapView"];
     if (!annotationView) {
        annotationView = [[MAAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"mapView"];
     }

    //設(shè)置大頭針的樣式為一張圖片
    annotationView.image = [UIImage imageNamed:@"pig1"];
    //讓氣泡顯示
    annotationView.canShowCallout = YES;
    //設(shè)置是否拖拽
    annotationView.draggable = YES;
    return annotationView;
}

#pragma mark- 畫折線 糠排,一般用于路徑規(guī)劃

-(void)drawLine
{
    //構(gòu)造折線的數(shù)據(jù)點
    CLLocationCoordinate2D commonPolylineCoords[4];
    commonPolylineCoords[0].latitude = 39.832136;
    commonPolylineCoords[0].longitude = 116.34095;
    commonPolylineCoords[1].latitude = 39.832136;
    commonPolylineCoords[1].longitude = 116.42095;
    commonPolylineCoords[2].latitude = 39.902136;
    commonPolylineCoords[2].longitude = 116.42095;

    commonPolylineCoords[3].latitude = 39.902136;
    commonPolylineCoords[3].longitude = 116.44095;

    //構(gòu)造折線對象
    //參數(shù)一:多個點組成的類似數(shù)組的經(jīng)緯度數(shù)據(jù)
    //參數(shù)二:構(gòu)成折線總共涉及到幾個點
    MAPolyline * polyLine = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:4];
    //將覆蓋圖層添加到地圖上
    [_mapView addOverlay:polyLine];
}

#pragma mark - 畫多邊形,一般用于精確的搜索

-(void)drawGon
{
    //構(gòu)造多邊形數(shù)據(jù)
    CLLocationCoordinate2D coordinates[4];
    coordinates[0].latitude = 39.810892;
    coordinates[0].longitude = 116.233413;

    coordinates[1].latitude = 39.816600;
    coordinates[1].longitude = 116.331842;

    coordinates[2].latitude = 39.762187;
    coordinates[2].longitude = 116.357932;

    coordinates[3].latitude = 39.733653;
    coordinates[3].longitude = 116.278255;

    MAPolygon * polyGon = [MAPolygon polygonWithCoordinates:coordinates count:4];
   [_mapView addOverlay:polyGon];
}

#pragma mark - 畫圓超升,一般用于模糊搜索

-(void)drawCircle
{
    //需要原點和半徑
    MACircle * circle = [MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(39.952136, 116.50095) radius:5000];
    [_mapView addOverlay:circle];
}

#pragma mark - 實現(xiàn)覆蓋圖層樣式的代理方法

-(MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay
{
     //舊版的返回值是MAOverLayView入宦,新版的是MAOverlayRenderer
     //畫折線
     if ([overlay isKindOfClass:[MAPolyline class]]) {
           MAPolylineRenderer * polyLine = [[MAPolylineRenderer alloc]initWithPolyline:overlay];
           //設(shè)置屬性
           //設(shè)置線寬
           polyLine.lineWidth = 5;
           //設(shè)置填充顏色
           polyLine.fillColor = [UIColor redColor];
           //設(shè)置筆觸顏色
           polyLine.strokeColor = [UIColor greenColor];
           //設(shè)置斷點類型
           polyLine.lineCapType = kMALineCapRound;
           return polyLine;
      } else if([overlay isKindOfClass:[MAPolygon class]])
      {
          MAPolygonRenderer * polyGon = [[MAPolygonRenderer alloc]initWithPolygon:overlay];
          polyGon.fillColor = [UIColor redColor];
          polyGon.strokeColor = [UIColor yellowColor];
          //設(shè)置顯示未虛線
          polyGon.lineDash = YES;
          polyGon.lineWidth = 8;
          return polyGon;
      } else if([overlay isKindOfClass:[MACircle class   ]])
      {
          MACircleRenderer * circle = [[MACircleRenderer alloc]initWithCircle:overlay];
          circle.fillColor = [UIColor blueColor];
          circle.strokeColor = [UIColor yellowColor];
          circle.lineWidth = 5;
          circle.lineDash = YES;
          return circle;
      }
      return nil;
}

定位

- (void)viewDidLoad {
     [super viewDidLoad];
     //配置用戶key
     [AMapLocationServices sharedServices].apiKey = @"e51bdf2a028ff1a08da5f20f114ff3c0";
     //初始化定位
     _manager = [[AMapLocationManager alloc]init];
     //設(shè)置代理
     _manager.delegate = self;
     //開啟定位
    [_manager startUpdatingLocation];
}
//定位的目的是為了拿到經(jīng)緯度值,iOS8之后更新的定位代理方法
-(void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location
{
     NSLog(@"經(jīng)緯度值~~~%f---%f",location.coordinate.longitude,location.coordinate.latitude);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市室琢,隨后出現(xiàn)的幾起案子乾闰,更是在濱河造成了極大的恐慌,老刑警劉巖盈滴,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件涯肩,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機病苗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門疗垛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人硫朦,你說我怎么就攤上這事贷腕。” “怎么了咬展?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵泽裳,是天一觀的道長。 經(jīng)常有香客問我挚赊,道長诡壁,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任荠割,我火速辦了婚禮妹卿,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蔑鹦。我一直安慰自己夺克,他們只是感情好,可當我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布嚎朽。 她就那樣靜靜地躺著铺纽,像睡著了一般。 火紅的嫁衣襯著肌膚如雪哟忍。 梳的紋絲不亂的頭發(fā)上狡门,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天,我揣著相機與錄音锅很,去河邊找鬼其馏。 笑死,一個胖子當著我的面吹牛爆安,可吹牛的內(nèi)容都是我干的叛复。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼扔仓,長吁一口氣:“原來是場噩夢啊……” “哼褐奥!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起翘簇,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤撬码,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后缘揪,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體耍群,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡义桂,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了蹈垢。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片慷吊。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖曹抬,靈堂內(nèi)的尸體忽然破棺而出溉瓶,到底是詐尸還是另有隱情,我是刑警寧澤谤民,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布堰酿,位于F島的核電站,受9級特大地震影響张足,放射性物質(zhì)發(fā)生泄漏触创。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一为牍、第九天 我趴在偏房一處隱蔽的房頂上張望哼绑。 院中可真熱鬧,春花似錦碉咆、人聲如沸抖韩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽茂浮。三九已至,卻和暖如春壳咕,著一層夾襖步出監(jiān)牢的瞬間席揽,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工谓厘, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留驹尼,地道東北人。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓庞呕,卻偏偏與公主長得像,于是被迫代替她去往敵國和親程帕。 傳聞我的和親對象是個殘疾皇子住练,可洞房花燭夜當晚...
    茶點故事閱讀 44,592評論 2 353

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