本文实例为大家分享了ios将地址解析成经纬度的具体代码,供大家参考,具体内容如下
一、工程图
二、代码
viewcontroller.h
1
2
3
4
5
6
7
8
|
#import <uikit/uikit.h> #import <corelocation/corelocation.h> #import <corelocation/cllocationmanagerdelegate.h> @interface viewcontroller : uiviewcontroller <cllocationmanagerdelegate> @end |
viewcontroller.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#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 |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.cnblogs.com/yang-guang-girl/archive/2017/08/14/7356203.html