編輯:看起來不再需要API密鑰。
您可以使用REST APIs和解析響應(XML/JSON/CSV)。
http://maps.google.com/maps/geo?q=State+St,+Troy,+NY&output=csv&oe=utf8&sensor=false
將輸出:
200,6,42.730070,-73.690570
那就是:
- - G_GEO_SUCCESS
- - 街道級精確度
- 42.730070 - 緯度
- -73.690570 - 經度
如果你不熟悉的System.Net的API,他們會去是這樣的:
const string GeoCodeUrlFormat = "http://maps.google.com/maps/geo?q={0}&output=csv&oe=utf8&sensor=false";
string location = "State St, Troy, NY";
string url = String.Format(GeoCodeUrlFormat, HttpUtility.UrlEncode(location));
HttpRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpResponse response = (HttpResponse)request.GetResponse(); // Can throw an exception
Stream responseStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream)
{
string firstLine = reader.ReadLine();
string[] lineParts = firstLine.Split();
GeolocationResult result = GoogleMapper.MapGeolocationResult(lineParts);
// TADA
}
顯然沒有錯誤處理,它不支持多個返回值,我沒有實際實現MapGeolocationResult,但它應該給你一個開始。
非常感謝。然而問題的一部分是我想使用V3的V3(不是V2),因爲它不再需要API密鑰。 該應用將推出到各種客戶和API密鑰應鏈接到網絡服務器,但這不會是一個Windows窗體應用程序的情況下... – Marc 2009-07-29 15:16:41