【问题标题】:How can I determine a CLLocation or MKPlacemark from an address?如何从地址中确定 CLLocation 或 MKPlacemark?
【发布时间】:2010-11-29 22:09:07
【问题描述】:

我看过 API 文档和演示后演示如何进行反向地理编码 - 获取地址,给定纬度/经度位置。我需要做相反的事情。我假设这已经解决了问题,因为 Apple 的 MapKit API 完全避免了它。

【问题讨论】:

    标签: iphone iphone-sdk-3.0 mapkit geocoding


    【解决方案1】:

    一种方法是像这样使用谷歌网络服务:

    -(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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      相关资源
      最近更新 更多