所以我试图做的是基本上调用谷歌地图webservice发送我的经度和纬度,我会得到我的位置的详细信息。例如街道名称和地址。
代码最初工作,直到它开始提供“远程服务器返回错误:NotFound”的错误消息。
所以试图解决这个问题我做了另一个简单的事情,其唯一的功能是发送谷歌地图API请求如下
MainPage.xaml,它只包含一个文本块和一个按钮。该按钮将简单地发送请求,结果将打印在文本块中。所以我想不需要在这里展示
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using GetStreetName.Resources;
namespace GetStreetName
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(getStreet_DownloadStringCompleted);
webClient.Headers["Accept"] = "application/json";
webClient.DownloadStringAsync(new Uri("https://maps.googleapis.com/maps/api/geocode/json?latlng=51.480837,-0.190243&sensor=true"));
}
private void getStreet_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Cancelled == true)
{
streetLabel.Text = "Download cancelled.";
return;
}
if (e.Error != null)
{
streetLabel.Text = e.Error.Message;
return;
}
MessageBox.Show(e.Result);
streetLabel.Text = e.Result;
}
// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
// // Set the page's ApplicationBar to a new instance of ApplicationBar.
// ApplicationBar = new ApplicationBar();
// // Create a new button and set the text value to the localized string from AppResources.
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);
// // Create a new menu item with the localized string from AppResources.
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}
经度和纬度只是通向切尔西足球俱乐部球场的虚拟价值。 无论如何,如果您尝试在某种REST控制台中使用相同的URL,它将完全正常工作。
有什么建议吗?提前致谢