본문 바로가기

iOS Programming

경도/위도 좌표로 주소 알아내기

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
self.mapAddress = @"";
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSString *str = [NSString stringWithFormat:@""];
str = [str stringByAppendingFormat:@"%@", placemark.country];
if([placemark.administrativeArea length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.administrativeArea];
}
if([placemark.subAdministrativeArea length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.subAdministrativeArea];
}
if([placemark.locality length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.locality];
}
if([placemark.subLocality length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.subLocality];
}
if([placemark.thoroughfare length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.thoroughfare];
}
if([placemark.subThoroughfare length] > 0)
{
str = [str stringByAppendingFormat:@" "];
str = [str stringByAppendingFormat:@"%@", placemark.subThoroughfare];
}

self.mapAddress = str;    // 최종 주소
}

- (IBAction)moveCurrent:(id)sender
{
    MKReverseGeocoder *everseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:위도경도로케이션] autorelease];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];
}