일상+

mapView에서 좌표로 주소구하기 본문

iPhone

mapView에서 좌표로 주소구하기

이종준 2015. 5. 12. 10:02

CLGeocoder *myGeocoder = [[CLGeocoder alloc]init];
        CLLocation *cl = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        [myGeocoder reverseGeocodeLocation:cl completionHandler:^(NSArray *placemarks, NSError *error)
        {
                 CLPlacemark *placemark = [placemarks objectAtIndex:0];
                 //we recieved the results
                 NSLog(@"Country = %@",placemark.country);
                 NSLog(@"Postal Code = %@",placemark.postalCode);
                 NSLog(@"Locality = %@",placemark.locality);
                 NSLog(@"administrativeArea : %@",placemark.administrativeArea);
                 NSLog(@"subAdministrativeArea : %@",placemark.subAdministrativeArea);
                 NSLog(@"ISOcountryCode : %@",placemark.ISOcountryCode);
                 NSLog(@"ocean : %@",placemark.ocean);
                 NSLog(@"subLocality : %@",placemark.subLocality);
                 NSLog(@"subThoroughfare : %@",placemark.subThoroughfare);
                 NSLog(@"thoroughfare : %@",placemark.thoroughfare);
                 NSLog(@"inlandWater : %@",placemark.inlandWater);
                 
                 NSMutableDictionary *addrDic = [[NSMutableDictionary alloc] initWithDictionary:placemark.addressDictionary];
                 [addrDic removeObjectForKey:@"Country"];
                 [addrDic removeObjectForKey:@"CountryCode"];
                 [addrDic removeObjectForKey:@"ZIP"];
                 nowAddrStr = ABCreateStringWithAddressDictionary(addrDic, NO);
                 
                 Annotation *annot = [[Annotation alloc] initWithLatitude:coordinate.latitude//[[dic valueForKey:@"lat"]doubleValue]
                                                                longitude:coordinate.longitude//[[dic valueForKey:@"lon"]doubleValue]
                                                                    title:[dic valueForKey:@"name"] 
                                                                 subtitle:nowAddrStr];//[dic valueForKey:@"nick_name"]];
                 
                 annot.sUserName = [dic valueForKey:@"name"]; //이름으로 누군지 구분해야쥥~~ 
                 [annotationArr addObject:annot];
                 [self.mapView addAnnotation:annot];
                 [annot release];
               
        }];

Comments