2013-01-22 187 views
1

我正在使用Windows Phone 8應用程序,但我無法找到,如何獲取座標表單地址。 問題是,我有我的座標,我需要計算我和一些地址之間的距離。如何從街道地址獲取座標

windows phone 8沒有記錄太多,所以請幫助我。

+0

可能重複[如何將地址(作爲文本)轉換爲GPS座標?](http://stackoverflow.com/questions/6996577/how-to-convert-address-as-text-to-gps-coordinates) –

+0

在這個話題中,在其他語言中是anwser,而不是在c#中,以及許多c odes工作在wp7.5而不是wp8上。 –

回答

7

您要查找的內容稱爲「地理編碼」:將地址轉換爲GeoCoordinate。

如前所述,您可以在WP7上使用Google和Bing來實現這一點。在Windows Phone 8上,支持將地理編碼和反向地理編碼作爲框架的一部分。您可以閱讀GeoCoding at this Nokia intro article(在「地理編碼」下)和更全面的概述at this other Nokia article的概述。

這裏的地理編碼的從地址轉換爲例座標:

private void Maps_GeoCoding(object sender, RoutedEventArgs e) 
{ 
    GeocodeQuery query = new GeocodeQuery() 
    { 
     GeoCoordinate = new GeoCoordinate(0, 0), 
     SearchTerm = "Ferry Building, San-Francisco" 
    }; 
    query.QueryCompleted += query_QueryCompleted; 
    query.QueryAsync(); 
} 

void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e) 
{ 
    StringBuilder sb = new StringBuilder(); 
    sb.AppendLine("Ferry Building Geocoding results..."); 
    foreach (var item in e.Result) 
    { 
     sb.AppendLine(item.GeoCoordinate.ToString()); 
     sb.AppendLine(item.Information.Name); 
     sb.AppendLine(item.Information.Description); 
     sb.AppendLine(item.Information.Address.BuildingFloor); 
     sb.AppendLine(item.Information.Address.BuildingName); 
     sb.AppendLine(item.Information.Address.BuildingRoom); 
     sb.AppendLine(item.Information.Address.BuildingZone); 
     sb.AppendLine(item.Information.Address.City); 
     sb.AppendLine(item.Information.Address.Continent); 
     sb.AppendLine(item.Information.Address.Country); 
     sb.AppendLine(item.Information.Address.CountryCode); 
     sb.AppendLine(item.Information.Address.County); 
     sb.AppendLine(item.Information.Address.District); 
     sb.AppendLine(item.Information.Address.HouseNumber); 
     sb.AppendLine(item.Information.Address.Neighborhood); 
     sb.AppendLine(item.Information.Address.PostalCode); 
     sb.AppendLine(item.Information.Address.Province); 
     sb.AppendLine(item.Information.Address.State); 
     sb.AppendLine(item.Information.Address.StateCode); 
     sb.AppendLine(item.Information.Address.Street); 
     sb.AppendLine(item.Information.Address.Township); 
    } 
    MessageBox.Show(sb.ToString()); 
} 

當我跑我的WP8這個代碼片斷,我得到了以下信息框:中

MEssageBox showing details for the ferry building

+0

你是最棒的!!! –

0

Bing地圖REST服務,還提供功能從指定的地址獲得緯度/長,更多信息可以在MSDN here

被發現

您需要獲取綁定地圖鍵here...