2011-01-24 7 views
0

可能性の重複:
Forward Geocode Example using CLGeocoderXcode iOS 4.2.1 - >地図を表示ピンを表示するアドレスを表示しますか?

私は名前とそのadrressesの完全なplistを持っています。私は自分のiOSアプリに、自分が選んだ人の住所がピンにマップビューで表示されるようにしたい。住所を地図表示にインポートしてピンを取得することはできますか?そしてどうやって??ありがとうございました。

+0

'[[のUIApplication sharedApplication]のOpenURL:[NSURL URLWithString:[NSStringのstringWithFormat:@ "http://maps.google.com/maps?q=%@&z=15"、yourAddress]]]; 'はうまくいきますが、あなたが送ることができるものは少し限られています。 Webブラウザでは、常に同じURLを使用してテストすることができます。私はあなたが名前を含めると結果が得られるのではないかと疑いますが、完全なアドレスはMaps.appを開いてピンを正しく配置します。 – runmad

+0

maps.google.com URLを使用してもiOS6のApple Mapsアプリケーションは開かず、代わりにWebブラウザが開きます。 –

答えて

-1

これは、前方ジオコーディングと呼ばれ、これを行うためのAPIは組み込まれていません。外部サービスを使用する必要があります。外部サービスは、実際にはアプリに依存します。

私はこれにGoogleのサービスを使用しました。 http://code.google.com/apis/maps/documentation/geocoding/

これは非常に簡単なAPIですが、アプリのライセンスに基づく制限があります。私はこれのためのカップルの他のサービスがあることを知っていますが、私はあなたに運動としてそれを残します。

0

緯度/経度座標にアドレスを変換するCLGeocoderクラスを使用します。

Forward Geocode Example using CLGeocoder

あなたが持っているより正確なアドレス、良い結果はあなたが非常に正確なポイントを取得する必要があり、正確なアドレスを持つようにする必要があります。

0

GoogleのジオコーディングWebサービスを使用する場合は、アドレス文字列をこの関数に渡すだけで、緯度が&経度のCLLocationCoordinate2Dが得られます。

今では最も近い一致結果である0番目のインデックスで位置を取得します。結果をログアウトしてGoogleからのJSONレスポンスを確認してください。

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address 
{ 
    NSString *esc_addr = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=true&address=%@", esc_addr]; 
    CLLocationCoordinate2D center; 


    NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL]; 
    if (result) 
    { 
     //NSLog(@"LOC RESULT: %@", result); 
     NSError *e; 
     NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData: [result dataUsingEncoding:NSUTF8StringEncoding] 
                    options: NSJSONReadingMutableContainers 
                    error: &e]; 
     NSArray *resultsArray = [resultDict objectForKey:@"results"]; 

     if(resultsArray.count > 0) 
     { 
      resultDict = [[resultsArray objectAtIndex:0] objectForKey:@"geometry"]; 
      resultDict = [resultDict objectForKey:@"location"]; 
      center.latitude = [[resultDict objectForKey:@"lat"] floatValue]; 
      center.longitude = [[resultDict objectForKey:@"lng"] floatValue]; 
     } 
     else 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results Found" message:@"No locations were found using, please try again." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
      [alert show]; 
     } 

     //goes through each result 
     /*for(NSDictionary *dict in resultsArray) 
     { 
      resultDict = [dict objectForKey:@"geometry"]; 
      resultDict = [resultDict objectForKey:@"location"]; 
     }*/ 
    } 
    return center; 
} 
関連する問題