首页 > 移动平台 > 详细

iOS中城市定位功能的实现

时间:2015-11-12 19:38:29      阅读:352      评论:0      收藏:0      [点我收藏+]

引入框架:CoreLocation


.h文件

引入CoreLocation/CoreLocation.h

@interface WeatherViewController :UIViewController<</span>CLLocationManagerDelegate>{

    CLLocationManager* locationManager;

}

 

@property (strong, nonatomic) CLLocationManager* locationManager;

 

@end

 
 
.m文件

//开始定位

-(void)startLocation{

    self.locationManager = [[CLLocationManager alloc] init];

    self.locationManager.delegate = self;

    self.locationManager.desiredAccuracy =kCLLocationAccuracyBest;

    self.locationManager.distanceFilter = 10.0f;

    [self.locationManager startUpdatingLocation];

}

 

//定位代理经纬度回调

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

    

    [locationManager stopUpdatingLocation];

    NSLog(@"location ok");

 

    NSLog(@"%@",[NSString stringWithFormat:@"经度:%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 * placemark in placemarks) {

            

            NSDictionary *test = [placemark addressDictionary];

            //  Country(国家)  State(城市)  SubLocality(区)

            NSLog(@"%@", [test objectForKey:@"State"]);

        }

    }];

}

 

iOS中城市定位功能的实现

原文:http://www.cnblogs.com/fuunnyy/p/4959696.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!