这篇文章主要为大家详细介绍了iOS将地址解析成经纬度的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
编程基础网
本文标题为:iOS将地址解析成经纬度的方法
基础教程推荐
猜你喜欢
- 以代码实例总结iOS应用开发中数据的存储方式 2022-11-20
- Android zxing如何识别反转二维码详解 2022-11-08
- iOS对数组进行排序的实例代码 2023-03-16
- iOS统计项目的代码总行数 2022-11-01
- iOS微信分享后关闭发送成功提示并返回应用 2023-01-03
- Android自定义悬浮按钮效果 2023-04-22
- iOS的音频文件的格式转换示例 2023-06-11
- Kotlin的枚举与异常示例详解 2022-12-07
- 使用Android Studio创建OpenCV4.1.0 项目的步骤 2023-02-26
- Android自定义view实现圆形进度条效果 2023-05-26
