iOS 第三方 map 地圖

第一步 設(shè)置根控制器 ?添加導航欄信息 添加表格 ?設(shè)置代理 數(shù)據(jù)源

第二步 添加依賴庫

依賴庫

第三步?

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

{

? ? NSArray *_provinceArr;

}

@end

@implementation ViewController

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? //初始化

? ? _provinceArr = @[@"石家莊",@"北京",@"太原",@"濟南",@"西安"];

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

? ? return _provinceArr.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

? ? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

? ? if (!cell) {

? ? ? ? cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

? ? }

? ? cell.textLabel.text = _provinceArr[indexPath.row];

? ? return cell;

}

第四步

創(chuàng)建跳轉(zhuǎn)控制器 ?里面設(shè)置屬性

@property (nonatomic , copy)NSString *passProvince;//傳遞生輝的字符串

第五步 屬性傳值 跳轉(zhuǎn)

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

? ? //得到選中行對應的文本

? ? NSString *pro = _provinceArr[indexPath.row];

? ? //實例化地圖控制器

? ? mapViewController *mapa = [[mapViewController alloc]init];

? ? mapa.passProvince = pro;

? ? [self.navigationController pushViewController:mapa animated:YES];

}

第六步

#import <MapKit/MapKit.h>

#import <CoreLocation/CoreLocation.h>

@interface mapViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>

@property (nonatomic , strong)MKMapView *mapView;

//地理位置管理者

@property (nonatomic ,strong)CLLocationManager *locManger;

@end

@implementation mapViewController

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? self.mapView = [[MKMapView alloc]initWithFrame:self.view.frame];

? ? //衛(wèi)星+平面的混合模式

? ? self.mapView.mapType = MKMapTypeHybrid;

? ? self.mapView.mapType = MKMapTypeStandard;

? ? [self.view addSubview:self.mapView];

? ? self.mapView.delegate = self;

? ? //獲取當前位置按鈕的創(chuàng)建

? ? UIButton *currentBtn = [UIButton buttonWithType:UIButtonTypeCustom];

? ? currentBtn.frame = CGRectMake(10, self.view.frame.size.height - 80, 40, 40);

? ? [currentBtn setTitle:@"定位" forState:UIControlStateNormal];

? ? currentBtn.backgroundColor = [UIColor blueColor];

? ? [currentBtn addTarget:self action:@selector(currentBtnDidPress:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:currentBtn];

? ? //實例化位置管理利器對象

? ? self.locManger = [[CLLocationManager alloc]init];

? ? self.locManger.delegate = self; //設(shè)置代理

? ? //申請用戶授權(quán)

? ? [self.locManger requestAlwaysAuthorization];

}

-(void)currentBtnDidPress:(id)sender{

? ? //開始獲取位置信息 調(diào)用此方法后 協(xié)議中的方法才會執(zhí)

? ? [self.locManger startUpdatingLocation];

}

//獲取到位置信息后觸發(fā)的回調(diào)方法

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{

? ? //獲取當前位置

? ? CLLocation *curLoc = [locations lastObject];

? ? //獲取經(jīng)緯度

? ? CLLocationCoordinate2D curCoor = curLoc.coordinate;

? ? NSLog(@"經(jīng)度:%g,緯度:%g",curCoor.longitude,curCoor.latitude);

? ? //地圖顯示區(qū)域縮小

? ? MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(curCoor, 800, 800);

? ? [self.mapView setRegion:region animated:YES];

? ? //地址解析

? ? CLGeocoder *geocoder = [[CLGeocoder alloc]init];

? ? [geocoder reverseGeocodeLocation:curLoc completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

? ? ? ? //獲取其中一個地址信息

? ? ? ? CLPlacemark *plack = [placemarks lastObject];

? ? ? ? //做一個大頭針 定在當前位置上 錨點

? ? ? ? MKPointAnnotation *point = [[MKPointAnnotation alloc]init];

? ? ? ? point.title = plack.name;

? ? ? ? point.coordinate = curCoor;

? ? ? ? [self.mapView addAnnotation:point];

? ? }];

}

//用于設(shè)置錨點視圖的回調(diào)方法

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{

? ? static NSString *str = @"pin";

? ? MKPinAnnotationView *pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:str];

? ? //掉落效果

? ? pin.animatesDrop = YES;

? ? //泡泡效果

? ? pin.canShowCallout = YES;

? ? return pin;

}

設(shè)置 info.plist 里面 添加

授權(quán)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末见间,一起剝皮案震驚了整個濱河市忆首,隨后出現(xiàn)的幾起案子错沽,更是在濱河造成了極大的恐慌伪货,老刑警劉巖叶圃,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件趟济,死亡現(xiàn)場離奇詭異纷宇,居然都是意外死亡寄悯,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門艰争,熙熙樓的掌柜王于貴愁眉苦臉地迎上來坏瞄,“玉大人,你說我怎么就攤上這事甩卓○龋” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵逾柿,是天一觀的道長缀棍。 經(jīng)常有香客問我,道長机错,這世上最難降的妖魔是什么爬范? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮弱匪,結(jié)果婚禮上青瀑,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好斥难,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布枝嘶。 她就那樣靜靜地躺著,像睡著了一般蘸炸。 火紅的嫁衣襯著肌膚如雪躬络。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天搭儒,我揣著相機與錄音穷当,去河邊找鬼。 笑死淹禾,一個胖子當著我的面吹牛馁菜,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播铃岔,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼汪疮,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了毁习?” 一聲冷哼從身側(cè)響起智嚷,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎纺且,沒想到半個月后盏道,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡载碌,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年猜嘱,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片嫁艇。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡朗伶,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出步咪,到底是詐尸還是另有隱情论皆,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布猾漫,位于F島的核電站点晴,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏静袖。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一俊扭、第九天 我趴在偏房一處隱蔽的房頂上張望队橙。 院中可真熱鬧,春花似錦、人聲如沸捐康。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽解总。三九已至贮匕,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間花枫,已是汗流浹背刻盐。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留劳翰,地道東北人敦锌。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像佳簸,于是被迫代替她去往敵國和親乙墙。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

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

  • 一生均、簡介 <<UITableView(或簡單地說听想,表視圖)的一個實例是用于顯示和編輯分層列出的信息的一種手段 <<...
    無邪8閱讀 10,606評論 3 3
  • 概述在iOS開發(fā)中UITableView可以說是使用最廣泛的控件,我們平時使用的軟件中到處都可以看到它的影子马胧,類似...
    liudhkk閱讀 9,047評論 3 38
  • App.m ViewController *vc = [[ViewController alloc]init]; ...
    本澤馬閱讀 341評論 0 0
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,103評論 1 32
  • 肥月送我進候車室汉买,工作人員不讓,她念叨了兩遍-以前不是可以么漓雅。無法录别,她只好走了,又回頭看看我邻吞。趁檢驗箱子的間隙抬頭...
    大笑滄海閱讀 194評論 0 1