//
// 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
記錄一下今天的地圖代碼,火星坐標(biāo)和地球坐標(biāo)的問題
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來骡澈,“玉大人锅纺,你說我怎么就攤上這事±吲梗” “怎么了囤锉?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長护锤。 經(jīng)常有香客問我官地,道長,這世上最難降的妖魔是什么烙懦? 我笑而不...
- 正文 為了忘掉前任驱入,我火速辦了婚禮,結(jié)果婚禮上氯析,老公的妹妹穿的比我還像新娘亏较。我一直安慰自己,他們只是感情好掩缓,可當(dāng)我...
- 文/花漫 我一把揭開白布雪情。 她就那樣靜靜地躺著,像睡著了一般你辣。 火紅的嫁衣襯著肌膚如雪巡通。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼叉讥,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼!你這毒婦竟也來了饥追?” 一聲冷哼從身側(cè)響起图仓,我...
- 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎但绕,沒想到半個(gè)月后救崔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體惶看,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年六孵,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了纬黎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站孕索,受9級(jí)特大地震影響逛艰,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜搞旭,卻給世界環(huán)境...
- 文/蒙蒙 一散怖、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧选脊,春花似錦杭抠、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽丹诀。三九已至钝的,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間铆遭,已是汗流浹背硝桩。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像橄妆,于是被迫代替她去往敵國和親衙伶。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 成長記錄-連載(三十六) ——我的第一篇五千字長文芬沉,說了什么躺同,你一定想不到 并不是不想每天寫公眾號(hào),而是之前思考怎...
- 易效能E6-高靈華-臺(tái)州-周檢視 天使三階周檢視】 百日目標(biāo)檢視 目標(biāo)1:錄完家族財(cái)富傳承與保障 這周進(jìn)度第十七了...
- 自從入了農(nóng)藥的坑黄刚,大部分的比賽都在用王昭君车海。 首先,選擇王昭君的原因: 顏值高鞍鳌侍芝!漂亮啊埋同!凍一下可以慢慢打州叠!操作性...