windows phone7 用GSP得到的座標得到城市名稱

來源:互聯網
上載者:User

 

 

需要先引用:http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc/mex

後台代碼:

using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Net;<br />using System.Windows;<br />using System.Windows.Controls;<br />using System.Windows.Documents;<br />using System.Windows.Input;<br />using System.Windows.Media;<br />using System.Windows.Media.Animation;<br />using System.Windows.Shapes;<br />using Microsoft.Phone.Controls;<br />using GSPGetCity.GeocodeService;</p><p>namespace GSPGetCity<br />{<br /> public partial class MainPage : PhoneApplicationPage<br /> {<br /> // Constructor<br /> public MainPage()<br /> {<br /> InitializeComponent();<br /> } </p><p> private void button1_Click(object sender, RoutedEventArgs e)<br /> {<br /> GeocodeServiceClient client = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");</p><p> client.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(OnReverseGeocodeCompleted);</p><p> ReverseGeocodeRequest request = new ReverseGeocodeRequest();<br /> request.Credentials = new Credentials();<br /> request.Credentials.ApplicationId = "AjjGZGtCVs7lEuRn860kGigumg5hhJ8LqKXOIxpk1zwuxxQUgcrFDRWmrYfYCtFg";<br /> Location loc = new Location();<br /> loc.Latitude = 37.736025;<br /> loc.Longitude = 115.66153;<br /> request.Location = loc;<br /> client.ReverseGeocodeAsync(request);<br /> }<br /> private void OnReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e)<br /> {<br /> if (e.Error == null)<br /> {<br /> if (e.Result.Results.Count > 0)<br /> {<br /> GeocodeResponse response = e.Result;</p><p> this.textBlock1.Text = response.Results[0].DisplayName;<br /> System.Collections.ObjectModel.ObservableCollection<GeocodeResult> list = response.Results;<br /> string allName = "";<br /> foreach (GeocodeResult i in list)<br /> {<br /> allName += i.DisplayName + " ";<br /> }<br /> this.textBlock2.Text = allName;<br /> }<br /> else<br /> MessageBox.Show("沒有檢索到該地理位置所對應的地點");<br /> }<br /> }</p><p> }<br />}

 

在中國的座標只能到省, 不夠具體. 我設定的是河北衡水的座標, 得到的地址只能是china hebei,   不知道WP7在中國發布以後會不會好些.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.