根據經緯度反向地理編譯出地址信息(若是報錯:Error Domain=kCLErrorDomain Code=8 "(null)")

注意:Error Domain=kCLErrorDomain Code=8 "(null)" 若是出現這個錯誤  必定是 經緯度有問題   必定是 經緯度有問題 必定是 經緯度有問題git

- (void)reverseGeocoder{ //建立地理編碼對象
    CLGeocoder *geocoder=[[CLGeocoder alloc]init]; //經度
    NSString *longitude = @"116.4582890000"; //緯度
    NSString *latitude = @"39.9127500000"; //建立位置
    CLLocation *location=[[CLLocation alloc]initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]]; //根據經緯度反向地理編譯出地址信息
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *array, NSError *error){ if (array.count > 0){ CLPlacemark *placemark = [array objectAtIndex:0]; //獲取城市
            NSString *city = placemark.locality; if (!city) { //四大直轄市的城市信息沒法經過locality得到,只能經過獲取省份的方法來得到(若是city爲空,則可知爲直轄市)
                city = placemark.administrativeArea; } NSLog(@"city = %@", city);//瀋陽市
            NSLog(@"--%@",placemark.name);//黃河大道21號
            NSLog(@"++++%@",placemark.subLocality); //渾南區
            NSLog(@"country == %@",placemark.country);//中國
            NSLog(@"administrativeArea == %@",placemark.administrativeArea); //遼寧省
            NSString *addressStr = [NSString stringWithFormat:@"%@ %@ %@ %@",placemark.administrativeArea,city,placemark.subLocality,placemark.name]; NSLog(@"administrativeArea == %@",addressStr); } else if (error == nil && [array count] == 0) { NSLog(@"No results were returned."); } else if (error != nil) { NSLog(@"An error occurred = %@", error); } }]; }
相關文章
相關標籤/搜索