/**
*This function will be called after the user location is updated
*@param userLocation new user location
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
// locate the current city
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 ( @"The current coordinates are: % 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 ( @"Current city name------%@" ,city);
BMKOfflineMap * _offlineMap = [[BMKOfflineMap alloc] init];
// _offlineMap.delegate = self;//You can not
NSArray* records = [_offlineMap searchCity:city];
BMKOLSearchRecord* oneRecord = [records objectAtIndex:0];
//City code such as: Beijing is 131
NSInteger cityId = oneRecord.cityID;
NSLog ( @"Current city number------->%zd" ,cityId);
NSLog ( @"Which district of the current city------%@ " ,placemark.subLocality);
//Close the service after finding the current location city
// [_locService stopUserLocationService];
}
}
}];
}