iOS 位置与地图相关

1:通过 CoreLocation.framework 获取当前位置所在的城市(适用于iOS 5以上)

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        NSLog(@"%d",placemarks.count);
        for (CLPlacemark *placemark in placemarks) {
            NSLog(@"%@ %@ %@ %@",[placemark.addressDictionary objectForKey:@"City"],[placemark.addressDictionary objectForKey:@"Country"],[placemark.addressDictionary objectForKey:@"State"],[placemark.addressDictionary objectForKey:@"SubLocality"]);  
        }
    }];
    [manager stopUpdatingLocation];
}

注:在通过 CLLocationManager 的委托获取具体位置数据以后,通过 CLGeocoder 来获取相关城市信息.



你可能感兴趣的:(ios,地图相关)