iOS --百度地圖定位後獲取城市座標,城市名稱,區域名稱
/**
*使用者位置更新後,會呼叫此函式
*@param userLocation 新的使用者位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
//定位當前城市
BMKCoordinateRegion region;
region.center.latitude = userLocation.location.coordinate.latitude;
region.center.longitude = userLocation.location.coordinate
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
if (array.count > 0) {
CLPlacemark *placemark = [array objectAtIndex:0];
if (placemark != nil) {
NSString *city = placemark.locality;
NSLog(@"當前城市名稱------%@",city);
BMKOfflineMap
// _offlineMap.delegate = self;//可以不要
NSArray* records = [_offlineMap searchCity:city];
BMKOLSearchRecord* oneRecord = [records objectAtIndex:0];
//城市編碼如:北京為131
NSInteger cityId = oneRecord.cityID;
NSLog(@"當前城市編號-------->%zd",cityId);
NSLog(@"當前城市的 哪個區------%@ ",placemark.subLocality);
//找到了當前位置城市後就關閉服務
// [_locService stopUserLocationService];
}
}
}];
}