我正在使用Windows Phone 8應用程序,但我無法找到,如何獲取座標表單地址。 問題是,我有我的座標,我需要計算我和一些地址之間的距離。如何從街道地址獲取座標
windows phone 8沒有記錄太多,所以請幫助我。
我正在使用Windows Phone 8應用程序,但我無法找到,如何獲取座標表單地址。 問題是,我有我的座標,我需要計算我和一些地址之間的距離。如何從街道地址獲取座標
windows phone 8沒有記錄太多,所以請幫助我。
您要查找的內容稱爲「地理編碼」:將地址轉換爲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這個代碼片斷,我得到了以下信息框:中
你是最棒的!!! –
你有幾個選擇,我用它來完成這個使用的是一個網絡服務,GOOGLE,BING,YAHOO等。
在Bing(CUS是Windows phone)系統 需要密鑰來訪問Google地圖API一旦你有,你可以accese的WP7.1 SDK爲BING關鍵你可以在 http://www.microsoft.com/maps/developers/mobile.aspx
關鍵或者如果你不工作,使用位置API的REST服務 http://msdn.microsoft.com/en-us/library/ff701715.aspx
thanx老兄:) .. –
可能重複[如何將地址(作爲文本)轉換爲GPS座標?](http://stackoverflow.com/questions/6996577/how-to-convert-address-as-text-to-gps-coordinates) –
在這個話題中,在其他語言中是anwser,而不是在c#中,以及許多c odes工作在wp7.5而不是wp8上。 –