iOS将地址解析成经纬度的方法
程序员文章站
2023-12-18 21:12:22
本文实例为大家分享了ios将地址解析成经纬度的具体代码,供大家参考,具体内容如下
一、工程图
二、代码
viewcontroller.h
#import...
本文实例为大家分享了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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。