windows phone7 用GSP得到的坐标得到城市名称

 

 

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

后台代码:

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

 

在中国的坐标只能到省, 不够具体. 我设置的是河北衡水的坐标, 得到的地址只能是china hebei,   不知道WP7在中国发布以后会不会好些.

你可能感兴趣的:(Windows,Phone7,windows,phone,credentials,constructor,object,list,button)