문제

LAT/긴 위치가 주어지면 주소를 얻기 위해 리버스 지오 코드를 수행하는 방법에 대한 API 문서와 데모를 보았습니다. 반대로해야합니다. Apple의 Mapkit API가 완전히 피하기 때문에 이것이 이미 해결 된 문제라고 가정합니다.

도움이 되었습니까?

해결책

한 가지 방법은 다음과 같은 Google 웹 서비스를 사용하는 것입니다.

-(CLLocationCoordinate2D) addressLocation {
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                           [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSLog(@"locationString = %@",locationString);

    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    double latitude = 0.0;
    double longitude = 0.0;
    if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
/*      
        NSString *nameString = [NSString stringWithFormat:@"http://ws.geonames.org/findNearestAddress?lat=%f&lng=%f",latitude,longitude];
        NSString *placeName = [NSString stringWithContentsOfURL:[NSURL URLWithString:nameString]];
        NSLog(@"placeName = %@",placeName);
 */
    }
    else {
        //Show error
    }
    CLLocationCoordinate2D location;
    location.latitude = latitude;
    location.longitude = longitude;

    return location;

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top