どのように私はアドレスからCLLocationまたはMKPlacemarkを決定することができますか?

StackOverflow https://stackoverflow.com/questions/1451792

質問

緯度/経度の位置指定されたアドレスを、取得するために -

私は逆ジオコードを行う方法についてのデモの後にAPIドキュメントとデモを見てきました。私は逆を行う必要があります。私はAppleのMapKit APIは完全にそれを回避するので、これはすでに問題を解決していると仮定しています。

役に立ちましたか?

解決

一つの方法は、そのようにGoogleのWebサービスを使用することです

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