GPSLocation
来源:互联网 发布:cctv网络直播电视 编辑:程序博客网 时间:2024/05/17 01:29
locationManager:didUpdateLocations:
代理方法拿到的location不是准确的,偏移后的地理位置- MKMapViewDelegate方法
mapView: didUpdateUserLocation:
拿到的userLocation是准确的,没有经过偏移处理
详情参考https://www.v2ex.com/t/11666和http://blog.csdn.net/qxuewei/article/details/51611627
// 从给定地名返回经纬度坐标+ (CLLocation *)getCoordinate2DWithAddressString:(NSString *)string{ CLGeocoder *encoder = [[CLGeocoder alloc] init]; __block CLLocation* location; [encoder geocodeAddressString:string completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { if (error != nil || placemarks.count == 0) { // 如果有错误信息或者数组中获取地名元素数量为0 // 说明没有找到 NSLog(@"error:%@", [error localizedDescription]); }else { //编码成功,找到了具体位置 //去除地理信息数组中的第一个CLPlacemark NSLog(@"count=%ld", placemarks.count); location = [placemarks firstObject].location; for (CLPlacemark*mark in placemarks) { NSLog(@"纬度:%f, 经度:%f", mark.location.coordinate.latitude, mark.location.coordinate.longitude); } } }]; return location;}
华水- - -纬度:34.778751, 经度:113.795870
34.7798580000,113.7943800000
大圣- - -纬度34.765516,经度113.600688
广州塔- - -纬度:23.106487, 经度:113.324587
天安门- - -纬度:39.908692, 经度:116.397477
// 从给定经纬度坐标返回地名+ (NSDictionary *)getAddressStringWithCoordinate2D:(CLLocation *)location{ CLLocationCoordinate2D coordinate; // 天安门的经纬度 coordinate.latitude = 39.908692; coordinate.longitude = 116.397477; CLLocation *newLocation=[[CLLocation alloc]initWithLatitude:coordinate.latitude longitude: coordinate.longitude]; CLGeocoder *encoder = [[CLGeocoder alloc] init];// if (Coordinate2D == NULL) return NULL; __block NSDictionary *addressDic; [encoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { if (error != nil || placemarks.count == 0) { // 如果有错误信息或者数组中获取地名元素数量为0 // 说明没有找到 }else { CLPlacemark *mark = [placemarks firstObject]; addressDic = mark.addressDictionary; NSLog(@"Santa Clara%@", mark.addressDictionary); } }]; return addressDic;}
返回结果
{ City = Beijing; Country = China; CountryCode = CN; FormattedAddressLines = ( "East Chang'an Avenue Dongcheng", "Beijing China" ); Name = "Tian'anmen"; State = Beijing; Street = "East Chang'an Avenue"; SubLocality = Dongcheng; Thoroughfare = "East Chang'an Avenue";}
0 0
- GPSLocation
- 获取GPSLocation
- 生活加油
- [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数
- signal test
- 前端眼中的Go→我的第一个GO接口(一)
- linux常用的命令集合
- GPSLocation
- 关于路径搜寻的问题!为何不执行目前所在目录下的档案?
- 自动驾驶——未来智能交通的畅想
- day03--利用for循环做来一个小V字形(小练习)
- Ubuntu :装机指南
- [算法] 关于algs4 MSD.java 高位优先的字符串排序 的逐行代码解释
- UEFI 安装Ubuntu 16.04分区问题
- 在ThoughtWorks工作两个多月的总结
- 1002. Business (35)解题报告