IOS中使用百度地圖定位后獲取城市坐標,城市名稱,城市編號信息
/**當獲取到定位的坐標后,回調函數*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
BMKCoordinateRegion region;
region.center.latitude = userLocation.location.coordinate.latitude;
region.center.longitude = userLocation.location.coordinate.longitude;
region.span.latitudeDelta = 0;
region.span.longitudeDelta = 0;
NSLog(@"當前的坐標是:%f,%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation: userLocation.location completionHandler:^(NSArray *array, NSError *error) {
if (array.count > 0) {
CLPlacemark *placemark = [array objectAtIndex:0];
if (placemark != nil) {
NSString *city = placemark.locality;
NSLog(@"當前城市名稱------%@",city);
BMKOfflineMap * _offlineMap = [[BMKOfflineMap alloc] init];
_offlineMap.delegate = self;//可以不要
NSArray* records = [_offlineMap searchCity:city];
BMKOLSearchRecord* oneRecord = [records objectAtIndex:0];
//城市編碼如:北京為131
NSInteger cityId = oneRecord.cityID;
NSLog(@"當前城市編號-------->%zd",cityId);
//找到了當前位置城市后就關閉服務
[_locService stopUserLocationService];
}
}
}];
}