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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

iOS定位服务与地图开发(3)---地理信息编码查询

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS定位服务与地图开发(3)---地理信息编码查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

即根據一個NSString的文字描述對象獲取相關的地理坐標。

采用CLGeocoder類操作,具體方法:

1>geocodeAddressDictionary:completionHandler: 通過指定一個地址信息字典對象參數進行查詢

2>geocodeAddressString:completionHandler:通過指定一個地址信息字符串參數進行查詢

3>geocodeAddressString:inRegion:completionHandler:通過制定地址信息字符串和查詢范圍進行查詢

- (IBAction)geocodeQuery:(id)sender {NSString *queryStr = nil;// 從界面文本框輸入地址字符串if (_textField.text == nil || [_textField.text length] == 0) {return ;}CLGeocoder *geocoder = [[CLGeocoder alloc] init];[geocoder geocodeAddressString:queryStr completionHandler:^(NSArray *placemarks, NSError *error) {NSLog(@"查詢記錄數:%i",[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];NSDictionary *addressDict = placemark.addressDictionary;NSString *address = [addressDict objectForKey:(NSString *)kABPersonAddressStreetKey];address = address == nil ? @"" : address;NSString *state = [addressDict objectForKey:(NSString *)kABPersonAddressStateKey];state = state == nil ? @"" : state;NSString *city = [addressDict objectForKey:(NSString *)kABPersonAddressCityKey];city = city == nil ? @"" : city;// 獲取地標對應的可讀的文字信息,一般返回到UI顯示NSString *streetInfo = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n",strCoordinate,state,address,city];}}]; }

使用geocodeAddressString:inRegion:completionHandler:指定查詢區域:

CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:_currLocation.coordinate radius:1000.0f identifier:@"GeocodeRegion"];CLGeocoder *geocoder = [[CLGeocoder alloc] init];[geocoder geocodeAddressString:queryStr inRegion:region completionHandler:^(NSArray *placemarks, NSError *error) {.......}];

CLRegion對象封裝了一個地理區域類。

構造方法參數:

center:指定區域中心點

radius:指定區域半徑,單位為米

identifier:為區域指定一個標識

?

轉載于:https://www.cnblogs.com/yaoxc/p/3721799.html

總結

以上是生活随笔為你收集整理的iOS定位服务与地图开发(3)---地理信息编码查询的全部內容,希望文章能夠幫你解決所遇到的問題。

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