日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS开发地理编码与反向编码

發布時間:2023/12/18 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发地理编码与反向编码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS開發地理編碼與反向編碼

#import <CoreLocation/CoreLocation.h>


選中項目導入相應的框架

// // LJReveceGeocoderViewController.m // 03-正向地理編碼與反向編碼 // // Created by 魯軍 on 2021/3/7. //#import "LJReveceGeocoderViewController.h" #import <CoreLocation/CoreLocation.h>@interface LJReveceGeocoderViewController ()@property (weak, nonatomic) IBOutlet UITextField *latitudeTF;@property (weak, nonatomic) IBOutlet UITextField *longitideTF;@property (weak, nonatomic) IBOutlet UILabel *cityLabel;@end@implementation LJReveceGeocoderViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.[self.longitideTF setText:@"116"];[self.latitudeTF setText:@"40"];} - (IBAction)reveceGeocoderClick:(id)sender {NSLog(@"12312");CLGeocoder *geocoder =[CLGeocoder new];CLLocation *location1 =[[CLLocation alloc] initWithLatitude:[self.latitudeTF.text doubleValue] longitude:[self.longitideTF.text doubleValue]];[geocoder reverseGeocodeLocation:location1 completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {if(placemarks.count ==0 || error){NSLog(@"解析error");}for(CLPlacemark *placemark in placemarks){self.cityLabel.text = placemark.locality;}}];}/* #pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller. } */@end // // LJGeocoderViewController.m // 03-正向地理編碼與反向編碼 // // Created by 魯軍 on 2021/3/7. //#import "LJGeocoderViewController.h" #import <CoreLocation/CoreLocation.h>@interface LJGeocoderViewController ()@property (weak, nonatomic) IBOutlet UITextField *addressTF;- (IBAction)geocoderClick:(id)sender;//緯度 @property (weak, nonatomic) IBOutlet UILabel *latitudeLabel; //經度 @property (weak, nonatomic) IBOutlet UILabel *longitudeLabel; @property (weak, nonatomic) IBOutlet UILabel *detailAddressLabel;@property(nonatomic,strong)CLLocationManager *mgr;@end@implementation LJGeocoderViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.addressTF.text = @"西三旗";} - (IBAction)geocoderClick:(id)sender {CLGeocoder *geocoder =[CLGeocoder new];[geocoder geocodeAddressString:self.addressTF.text completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {//placemarks 地標數組if(placemarks.count==0 || error){NSLog(@"解析有錯誤");return;}for(CLPlacemark *placemark in placemarks){NSLog(@"%lf",placemark.location.coordinate.latitude);NSLog(@"%lf",placemark.location.coordinate.longitude);NSLog(@"name = %@",placemark.name);NSLog(@"locality = %@",placemark.locality);self.latitudeLabel.text = [NSString stringWithFormat:@"%f",placemark.location.coordinate.latitude];self.longitudeLabel.text= [NSString stringWithFormat:@"%f",placemark.location.coordinate.longitude];self.detailAddressLabel.text = placemark.name;}}];} @end

總結

以上是生活随笔為你收集整理的IOS开发地理编码与反向编码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。