经纬度转换成城市信息

来源:互联网 发布:Mac退出无线诊断 编辑:程序博客网 时间:2024/05/04 10:51


-(void)getLocationTitleWithLocation:(CLLocation *)location

{

    //根据经纬度解析成位置

   CLGeocoder *geocoder=[[CLGeocoderalloc]init];

    [geocoderreverseGeocodeLocation:location completionHandler:^(NSArray *placemark,NSError *error)

     {

         //如果有错误信息,或者是数组中获取的地名元素数量为0,那么说明没有找到

        if (error || placemark.count==0) {

             //self.detailAddressLabel.text=@"你输入的地址没找到,可能在月球上";

         }else  //  编码成功,找到了具体的位置信息

         {

             //打印查看找到的所有的位置信息

            /*

                   name       :名称

                   locality   :城市

                   country    :国家

                   postalCode :邮政编码

              */

            for (CLPlacemark *placein placemark) {

                 

                NSLog(@"name=%@ locality=%@ country=%@ postalCode=%@",place.name,place.locality,place.country,place.postalCode);

                 

             }

             //取出获取的地理信息数组中的第一个显示在界面上

            CLPlacemark *firstPlacemark=[placemark firstObject];

             

            //详细地址名称

             //self.detailAddressLabel.text=firstPlacemark.name;

            //纬度

             //CLLocationDegrees latitude=firstPlacemark.location.coordinate.latitude;

            //经度

             CLLocationDegrees longitude=firstPlacemark.location.coordinate.longitude;

             //self.latitudeLabel.text=[NSString stringWithFormat:@"%.2f",latitude];

             //self.longitudeLabel.text=[NSString stringWithFormat:@"%.2f",longitude];

         }

     }];

}


0 0
原创粉丝点击