IOS之征战GPS(定位城市)

a.使用CoreLocation 定位得到经度和纬度

b.在-(void)locationManager:(CLLocationManager )manager didUpdateToLocation:(CLLocation )newLocation代理方法中使用CLGeocoder的reverseGeocodeLocation: :方法解析

c.在b中解析方法的完成回掉块completionHandler:^(NSArray *placemarks, NSError *error)中得到Country(国家) State(城市) SubLocality(区)

    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {  

        [locationManager stopUpdatingLocation];  
        NSLog(@"location ok");  

        CLGeocoder * geoCoder = [[CLGeocoder alloc] init];  
        [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {  
            for (CLPlacemark * placemark in placemarks) {  

                NSDictionary *test = [placemark addressDictionary];  
                // Country(国家) State(省) SubLocality(区)城市需要用place mark.locality获得 
                NSLog(@"%@", [test objectForKey:@"State"]);  
            }  
        }];  
    }  

你可能感兴趣的:(ios,gps,城市定位)