iOS将地址解析成经纬度 iOS将地址解析成经纬度的方法
弦外雨 人气:0想了解iOS将地址解析成经纬度的方法的相关内容吗,弦外雨在本文为您仔细讲解iOS将地址解析成经纬度的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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
加载全部内容