Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
GPS, Location API and Calling Web Services - Day 3 - Part 10
Nov 26, 2010 at 12:56 AMI also tried and tried to get the service to work with no luck, none of the posted suggestions worked for me. So I decided to see if I could do this another way. I ran across Yahoo's PlaceFinder, it is implemented a little different in that it is a REST web service. More info can be found here:
Yahoo! PlaceFinder Guide
I should point out I am an Absolute Beginner, thus why I am watching this series, so if there is a better way todo this I would love the insight. Here is the code I came up with:
private void myButton_Click(object sender, RoutedEventArgs e) { GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher(); var myPosition = myWatcher.Position; string latitude = "47.674"; string longitude = "-122.12"; if (!myPosition.Location.IsUnknown) { latitude = myPosition.Location.Latitude.ToString(); longitude = myPosition.Location.Latitude.ToString(); } Uri uri = new Uri("http://where.yahooapis.com/geocode?&gflags=R&location=" + latitude + "+" + longitude); WebClient wc = new WebClient(); wc.DownloadStringCompleted += OnDownloadStringCompleted; wc.DownloadStringAsync(uri); } private void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs args) { if (args.Error == null) { XDocument xdoc = XDocument.Parse(args.Result); //Get the City myTextBlock.Text = xdoc.Element("ResultSet").Element("Result").Element("city").Value.ToString(); //Get the State //myTextBlock.Text = xdoc.Element("ResultSet").Element("Result").Element("state").Value.ToString(); //Get the City, State, Zip //myTextBlock.Text = xdoc.Element("ResultSet").Element("Result").Element("line2").Value.ToString(); //Get the Country //myTextBlock.Text = xdoc.Element("ResultSet").Element("Result").Element("country").Value.ToString(); } }You will need to add a reference to your project for System.Xml.Linq so that you can parse the XML data that is returned from Yahoo. And if you plan on using this as a solution you will need to get a developer ID from Yahoo to use it, refer to the link above about this.
I do like the flexibility of the XML returned and that I can grab just the city or state. Hopefully this will help someone else out struggling with the Microsoft Service.
****NOTE**** the code block seems to be messing up my Uri address. It should be:
Uri uri = new Uri("http://where.yahooapis.com/geocode?&gflags=R&location=" + latitude + "+" + longitude);
-Shelby