#import"ViewController.h"
//导入
#import
#import
//设置代理
@interfaceViewController()
@property(nonatomic,strong)CLLocationManager*locationManager;
//点击获取位置button
@property(nonatomic,strong)UIButton*locationButton;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
_locationButton= [UIButtonbuttonWithType:UIButtonTypeCustom];
_locationButton.frame=CGRectMake(0,100,self.view.bounds.size.width,self.view.bounds.size.width);
_locationButton.backgroundColor= [UIColorredColor];
[_locationButtonsetTitle:@"定位"forState:UIControlStateNormal];
[_locationButtonsetTitleColor: [UIColorwhiteColor]forState:UIControlStateNormal];
[self.viewaddSubview:_locationButton];
[_locationButtonaddTarget:selfaction:@selector(ButtonClickToLocation)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:_locationButton];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)ButtonClickToLocation
{
self.locationManager= [[CLLocationManageralloc]init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
[self.locationManagerrequestAlwaysAuthorization];
self.locationManager.distanceFilter=10.0f;
[self.locationManagerstartUpdatingLocation];
}
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations
{
CLLocation*newLocation = locations[0];
CLLocationCoordinate2DoCoordinate = newLocation.coordinate;
NSLog(@"=旧经度:%f==旧纬度: %f",oCoordinate.longitude,oCoordinate.latitude);
[self.locationManagerstopUpdatingLocation];
//地理位置解码编码器对象
CLGeocoder*geoCoder = [[CLGeocoderalloc]init];
[geoCoderreverseGeocodeLocation:newLocationcompletionHandler:^(NSArray *_Nullableplacemarks,NSError*_Nullableerror) {
for(CLPlacemark*placeinplacemarks) {
NSDictionary*location = [placeaddressDictionary];
NSLog(@"位置信息======%@",location);
NSLog(@"位置信息====City%@==Country%@==CountryCode%@==FormattedAddressLines%@==Name%@==State%@==Street%@===SubLocality%@=====Thoroughfare%@",location[@"City"],location[@"Country"],location[@"CountryCode"],location[@"FormattedAddressLines"][0],location[@"Name"],location[@"State"],location[@"Street"],location[@"SubLocality"],location[@"Thoroughfare"]);
}
}];
}
简单获取定位-iOS
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 转载(http://www.cnblogs.com/oshushu/p/4569252.html) 1.概述由于公...
- 今天给大家补充一节上一篇文章有关的,定位我当前的详细地址的功能,给大家写一下,下面给大家先看一下效果 然后我们直接...
- 网上有很多关于隐藏的方法,设置后能够成功,但是跳转到其他界面的时候发现,其他界面横线也被隐藏了。目前主流的方法是将...
- 20171106一号根据地评薛兆丰北大经济学 最低零售价很多时候能够在确保产品的质量抱持稳定,因为价格的规定就确保...