/**
* 初始化定位
*/
- (void)paepareLocation {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLLocationAccuracyThreeKilometers;
[self.locationManager startUpdatingLocation];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
/**
* 定位成功
*/
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *location = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude
longitude:newLocation.coordinate.longitude];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"error: %@", error);
return;
}
NSLog(@"定位成功");
CLPlacemark *placemark1 = [placemarks objectAtIndex:0];
[self showData:placemark1.addressDictionary];
}];
NSLog(@"firstviewctroller 定位成功latitude = %f",newLocation.coordinate.latitude);
NSLog(@"longitude = %f",newLocation.coordinate.longitude);
_longitude = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
_latitude = [ NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
}
/**
* 显示定位信息
*
* @param dic 位置数据
*/
-(void)showData:(NSDictionary *)dic
{
_addressLabel.text =[NSString stringWithFormat:@"%@",[dic objectForKey:@"City"]];
NSArray *array = [dic objectForKey:@"FormattedAddressLines"];
NSString *str8 =[NSString stringWithFormat:@"%@",[array objectAtIndex:0]];
NSLog(@"FormattedAddressLines = %@",str8);
}
热门文章更多>>
标签更多>>
专题更多>>
最新文章更多>>
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
- 使用 C# 6.0 功能运行 TFS 构建
叫我小瘦子-