CLLocationManager 定位

来源:互联网 发布:java怎么定义一个方法 编辑:程序博客网 时间:2024/06/05 08:39

 self.locationManager=[[CLLocationManageralloc]init];

    self.locationManager.delegate=self;

    [self.locationManagerstartUpdatingLocation];


-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{

  CLLocation *location=  [locations objectAtIndex:0];

     [self.locationManagerstopUpdatingLocation];

    CLGeocoder  *geocoder=   [[CLGeocoderalloc]init];


//位置反编码

    [geocoder reverseGeocodeLocation:locationcompletionHandler:^(NSArray *placemarks,NSError *error) {

     CLPlacemark   *placemark=[placemarks objectAtIndex:0];

      

        NSLog(@"\n name:%@\n  country:%@\n postalCode:%@\n ISOcountryCode:%@\n ocean:%@\n inlandWater:%@\n locality:%@\n subLocality:%@\n administrativeArea:%@\n subAdministrativeArea:%@\n thoroughfare:%@\n subThoroughfare:%@\n",

              placemark.name,

              placemark.country,

              placemark.postalCode,

              placemark.ISOcountryCode,

              placemark.ocean,

              placemark.inlandWater,

              placemark.administrativeArea,

              placemark.subAdministrativeArea,

              placemark.locality,

              placemark.subLocality,

              placemark.thoroughfare,

              placemark.subThoroughfare

              

              );

    }];

    //[self addLocationView:location];

   

}


打印  

 name:中国上海市宝山区淞南镇淞南淞良路301

  country:中国

 postalCode:(null)

 ISOcountryCode:CN

 ocean:(null)

 inlandWater:(null)

 locality:上海市

 subLocality:(null)

 administrativeArea:(null)

 subAdministrativeArea:宝山区

 thoroughfare:淞良路

 subThoroughfare:301



0 0
原创粉丝点击