私はASP.NET MVC 3とGoogle Maps v3を使用しています。私はアクションでジオコーディングをしたいと思います。それは有効なアドレスをGoogleに渡し、緯度と経度を戻します。私が見たジオコーディングに関するすべてのオンラインサンプルは、クライアントサイドのジオコーディングを扱っています。あなたはC#を使ったアクションでこれをどうやって行いますか?Google Maps v3ジオコーディングサーバー側
11
A
答えて
16
2
LBのソリューションは、働いていた拡張メソッドを使用して(あなたが興味を持っている場合)、私はそれを行う方法
void GoogleGeoCode(string address)
{
string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";
dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
foreach (var result in googleResults.results)
{
Console.WriteLine("[" + result.geometry.location.lat + "," + result.geometry.location.lng + "] " + result.formatted_address);
}
}
です私のために。しかし、私はいくつかのランタイムバインディングの問題に遭遇し、それらを使用する前に結果をキャストしなければならなかった
public static Dictionary<string, decimal> GoogleGeoCode(string address)
{
var latLong = new Dictionary<string, decimal>();
const string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";
dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
foreach (var result in googleResults.results)
{
//Have to do a specific cast or we'll get a C# runtime binding exception
var lat = (decimal)result.geometry.location.lat;
var lng = (decimal) result.geometry.location.lng;
latLong.Add("Lat", lat);
latLong.Add("Lng", lng);
}
return latLong;
}
関連する問題
- 1. Maps APIをV3:Google MapsのAPI V3で
- 2. google maps v3 around
- 3. Google Maps v3のスターサーチアルゴリズム
- 4. Google Maps API v3オーバーレイ
- 5. GWT + Google Maps API v3
- 6. Google Maps JavaScript API v3
- 7. Google Maps API V3 - ポリゴンスムージドエッジ
- 8. Google Maps API V3グレーエリア
- 9. Google Maps API V3プロットアドレス
- 10. Google Maps API V3 infowindow
- 11. google maps api v3 - マップデータホワイトブロックマップ
- 12. Google Maps API v3のチュートリアル
- 13. Google Maps v3マーカーシャドウzインデックス
- 14. Google Maps API v3マーカー座標
- 15. Google MapsのAPI V3 TrafficLayerウィジェット
- 16. Google Maps V3 in hidden div
- 17. Google Maps API v3:図面マネージャ
- 18. PHPはGoogle Maps API V3内
- 19. MVC 4とGoogle Maps API v3
- 20. google maps api v3 expandボタン
- 21. Google Maps API v3 JS map.fitbounds
- 22. Google Maps API v3(PHPとJavascript)
- 23. google maps v3 marker titleプロパティ
- 24. どのV3 Google MapsのAPI
- 25. Google Maps API V3のエラー
- 26. は、infowindow google maps api(v3)
- 27. Google Maps Api V3 - StreetView enableCloseButton
- 28. Google Maps API v3ストリートビュー "google is not defined"
- 29. Google Maps API V3のマーカーをプロットする
- 30. Google Maps APIのV3:オーバーレイイメージマップのローディングインジケーター
ニース - 共有ありがとう。それはうまく動作します。あなたのサンプルはGoogle Maps v3を正しく使用していますか? – thd
いいえ、javascript APIではありません。私はhttp://code.google.com/apis/maps/documentation/geocoding/( 'JSON出力形式') –
からのドキュメントを使用しました。私はlatとlngをデータベーステーブルに保存する予定でしたが、これはまだ動作しますか? – RyeNyeTheComputerScienceGuy