zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-将地址解析成经纬度

    一,工程图。

    二,代码。

    ViewController.h

    复制代码
    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>
    #import <CoreLocation/CLLocationManagerDelegate.h>
    
    @interface ViewController : UIViewController
    <CLLocationManagerDelegate>
    
    @end
    复制代码

     

    ViewController.m

    复制代码
    #import "ViewController.h"
    #import <CoreLocation/CoreLocation.h>
    #import <AddressBook/AddressBook.h>
    
    
    //正编译。将地址解析为经纬度
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder geocodeAddressString:@"上海徐汇漕溪路" completionHandler:^(NSArray *placemarks, NSError *error){
            NSLog(@"查询记录数:%ld",[placemarks count]);
            if ([placemarks count] > 0) {
                CLPlacemark *placemark = [placemarks objectAtIndex:0];
                CLLocationCoordinate2D coordinate = placemark.location.coordinate;
                
                NSString *strCoordinate = [NSString stringWithFormat:@"经度:%3.5f  纬度:%3.5f:",coordinate.latitude,coordinate.longitude ];
                NSLog(@"%@",strCoordinate);
            }
        }];
    
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    复制代码
  • 相关阅读:
    BZOJ3065(替罪羊树套线段树)
    BZOJ3052(树上带修莫队)
    BZOJ1095(动态点分治+堆)
    NOIWC颓废记
    BZOJ2125 最短路
    Simpson积分(BZOJ2178)
    BZOJ4555 [Tjoi2016&Heoi2016]求和
    NTT+多项式求逆+多项式开方(BZOJ3625)
    Miller-Rabin,Pollard-Rho(BZOJ3667)
    单纯形求解线性规划(BZOJ1061)
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/7356203.html
Copyright © 2011-2022 走看看