@interfaceWeatherViewController :UIViewController<</span>CLLocationManagerDelegate>{
CLLocationManager* locationManager;
}
@property (strong, nonatomic) CLLocationManager* locationManager;
@end
//开始定位
-(void)startLocation{
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 10.0f;
[self.locationManagerstartUpdatingLocation];
}
//定位代理经纬度回调
-(void)locationManager:(CLLocationManager *)managerdidUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation {
[locationManagerstopUpdatingLocation];
NSLog(@"location ok");
NSLog(@"%@",[NSStringstringWithFormat:@"经度:%3.5f\n纬度:%3.5f",newLocation.coordinate.latitude,newLocation.coordinate.longitude]);
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocationcompletionHandler:^(NSArray*placemarks, NSError *error){
for(CLPlacemark * placemarkin placemarks) {
NSDictionary *test = [placemarkaddressDictionary];
/*Country(国家) State(城市) SubLocality(区)*/
NSLog(@"%@", [test objectForKey:@"State"]);
}
}];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog([@"LocationManager didFailWithError" stringByAppendingString:[error localizedDescription]]);
}