iOS -- get city coordinates, city name, area name after positioning on Baidu map

/**

 *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];

                

                

                


                

            }

        }

    }];

    

    

    

}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325387353&siteId=291194637