記錄一下今天的地圖代碼,火星坐標(biāo)和地球坐標(biāo)的問題

//
//  ViewController.m
//  mapLearning
//
//  Created by Jin on 2016/12/6.
//  Copyright ? 2016年 Jin. All rights reserved.
//

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "JMLocationTransformer.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface ViewController () <MKMapViewDelegate>

@property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) CLLocationManager *manager;
@property (nonatomic, strong) UILabel *placeMarkerLabel;
@property (nonatomic, strong) UILabel *lonAndLatLabel;

@end

@implementation ViewController

- (UILabel *)lonAndLatLabel {
    if (!_lonAndLatLabel) {
        _lonAndLatLabel = [[UILabel alloc]initWithFrame:CGRectMake(8,SCREEN_HEIGHT - 76, SCREEN_WIDTH - 16, 30)];
        _lonAndLatLabel.backgroundColor = [UIColor whiteColor];
    }
    return _lonAndLatLabel;
}

- (UILabel *)placeMarkerLabel {
    if (!_placeMarkerLabel) {
        _placeMarkerLabel = [[UILabel alloc]initWithFrame:CGRectMake(8,SCREEN_HEIGHT - 38, SCREEN_WIDTH - 16, 30)];
        _placeMarkerLabel.backgroundColor = [UIColor whiteColor];
    }
    return _placeMarkerLabel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view.center = self.view.center;
    view.backgroundColor = [UIColor redColor];
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 5.0f;
    
    self.mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];
    self.mapView.delegate = self;
    [self.view addSubview:self.mapView];
    [self.mapView addSubview:self.lonAndLatLabel];
    [self.mapView addSubview:self.placeMarkerLabel];
    
    [self.view addSubview:view];

    self.manager = [[CLLocationManager alloc]init];
    [self.manager requestAlwaysAuthorization];
    [self.manager requestWhenInUseAuthorization];
    
    self.mapView.userTrackingMode = MKUserTrackingModeFollow;
//    CGPoint point = [self.mapView convertCoordinate:self.mapView.centerCoordinate toPointToView:self.mapView];
//    NSLog(@"Point = (%f,%f)",point.x,point.y);
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CLLocationCoordinate2D centerCoordinate = mapView.region.center;
    
    CLLocation *centerLocation = [[CLLocation alloc]initWithLatitude:centerCoordinate.latitude longitude:centerCoordinate.longitude];
//    self.lonAndLatLabel.text = [NSString stringWithFormat:@"longitude = %f,latitude = %f",centerCoordinate.longitude,centerCoordinate.latitude];
    
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    // 反地理編碼;根據(jù)經(jīng)緯度查找地名
    [geocoder reverseGeocodeLocation:centerLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if (placemarks.count == 0 || error) {
            NSLog(@"error");
            return;
        }
        CLPlacemark *pm = [placemarks firstObject];
        self.lonAndLatLabel.text = [NSString stringWithFormat:@"原生地標(biāo)%@",pm.name];
    }];
    
    CLLocationCoordinate2D transformCoordinate = [JMLocationTransformer transformFromWGSToGCJ:centerCoordinate];
    CLLocation *transformLocation = [[CLLocation alloc]initWithLatitude:transformCoordinate.latitude longitude:transformCoordinate.longitude];
    
    CLGeocoder *geocoder1 = [[CLGeocoder alloc] init];
    // 反地理編碼;根據(jù)經(jīng)緯度查找地名
    [geocoder1 reverseGeocodeLocation:transformLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if (placemarks.count == 0 || error) {
            NSLog(@"error");
            return;
        }
        CLPlacemark *pm = [placemarks firstObject];
        self.placeMarkerLabel.text = [NSString stringWithFormat:@"轉(zhuǎn)換地標(biāo)%@",pm.name];
    }];
    
//    self.placeMarkerLabel.text = [NSString stringWithFormat:@"longitude = %f,latitude = %f",transformCoordinate.longitude,transformCoordinate.latitude];
}

/*
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    
    // 反地理編碼;根據(jù)經(jīng)緯度查找地名
    [geocoder reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray *placemarks, NSError *error) {
        if (placemarks.count == 0 || error) {
            NSLog(@"找不到該位置");
            return;
        }
        
        // 當(dāng)前地標(biāo)
        CLPlacemark *pm = [placemarks firstObject];
        
        // 區(qū)域名稱
        userLocation.title = pm.locality;
        // 詳細(xì)名稱
        userLocation.subtitle = pm.name;
    }];
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市褒繁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖越除,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡廊敌,警方通過查閱死者的電腦和手機(jī)铜跑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來骡澈,“玉大人锅纺,你說我怎么就攤上這事±吲梗” “怎么了囤锉?”我有些...
    開封第一講書人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長护锤。 經(jīng)常有香客問我官地,道長,這世上最難降的妖魔是什么烙懦? 我笑而不...
    開封第一講書人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任驱入,我火速辦了婚禮,結(jié)果婚禮上氯析,老公的妹妹穿的比我還像新娘亏较。我一直安慰自己,他們只是感情好掩缓,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開白布雪情。 她就那樣靜靜地躺著,像睡著了一般你辣。 火紅的嫁衣襯著肌膚如雪巡通。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評(píng)論 1 302
  • 那天舍哄,我揣著相機(jī)與錄音宴凉,去河邊找鬼。 笑死蠢熄,一個(gè)胖子當(dāng)著我的面吹牛跪解,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播签孔,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼叉讥,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼!你這毒婦竟也來了饥追?” 一聲冷哼從身側(cè)響起图仓,我...
    開封第一講書人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎但绕,沒想到半個(gè)月后救崔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體惶看,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年六孵,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了纬黎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡劫窒,死狀恐怖本今,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情主巍,我是刑警寧澤冠息,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站孕索,受9級(jí)特大地震影響逛艰,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜搞旭,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一散怖、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧选脊,春花似錦杭抠、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽丹诀。三九已至钝的,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間铆遭,已是汗流浹背硝桩。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留枚荣,地道東北人碗脊。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像橄妆,于是被迫代替她去往敵國和親衙伶。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

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