zoukankan      html  css  js  c++  java
  • GeocodeLocation

    #import "ViewController.h"
    #import <CoreLocation/CoreLocation.h>
    
    @interface ViewController ()
    
    
    /** 地理编码 */
    @property (nonatomic, strong) CLGeocoder *geoC;
    @property (weak, nonatomic) IBOutlet UITextView *addressTV;
    
    @property (weak, nonatomic) IBOutlet UITextField *latitudeTF;
    
    @property (weak, nonatomic) IBOutlet UITextField *longitudeTF;
    @end
    
    @implementation ViewController
    
    
    #pragma mark -懒加载
    -(CLGeocoder *)geoC
    {
        if (!_geoC) {
            _geoC = [[CLGeocoder alloc] init];
        }
        return _geoC;
    }
    
    
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        //
        [self.view endEditing:YES];
    }
    
    /**
     *  地理编码(地址转经纬度)
     */
    - (IBAction)geoCoder {
        
        NSString *address = self.addressTV.text;
        
        // 容错
        if([address length] == 0)
            return;
        
        [self.geoC geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
            
            // CLPlacemark : 地标
            // location : 位置对象
            // addressDictionary : 地址字典
            // name : 地址详情
            // locality : 城市
            
            if(error == nil)
            {
                CLPlacemark *pl = [placemarks firstObject];
                self.addressTV.text = pl.name;
                self.latitudeTF.text = @(pl.location.coordinate.latitude).stringValue;
                self.longitudeTF.text = @(pl.location.coordinate.longitude).stringValue;
            }else
            {
                NSLog(@"错误");
            }
    
            
        }];
        
        
    }
    - (IBAction)reverseGeoCoder {
        
        // 获取用户输入的经纬度
        double latitude = [self.latitudeTF.text doubleValue];
        double longitude = [self.longitudeTF.text doubleValue];
        
        CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
        
        // 反地理编码(经纬度---地址)
        [self.geoC reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
            if(error == nil)
            {
                CLPlacemark *pl = [placemarks firstObject];
                self.addressTV.text = pl.name;
                self.latitudeTF.text = @(pl.location.coordinate.latitude).stringValue;
                self.longitudeTF.text = @(pl.location.coordinate.longitude).stringValue;
            }else
            {
                NSLog(@"错误");
            }
    
        }];
        
        
    }
    
    
    @end
    

      

  • 相关阅读:
    CV 第十一课 Segmentation Localization Detection 下
    面经
    overfitting问题
    CV 第十一课 Segmentation Localization Detection 上
    CV 第十一课 Classification + Localization 中
    SVM的特点
    UNSW CV第二课 上 Image Prepocessing
    UNSW CV Assignment1
    UNSW CV 第一课 下 投影 RGB HSV
    HDU 4350
  • 原文地址:https://www.cnblogs.com/yedayi/p/5137683.html
Copyright © 2011-2022 走看看