Bing maps rest api in windows phone 7

by sunil ravulapalli /25. October 2010 22:30 /windows-phone /Comments (1)

Get a Bing maps developer account here http://www.microsoft.com/maps/developers/web.aspx so that you can get your own Bing maps key.
If you want to get the route between two points, the code to call the web service looks like this:

 string bingUri
  ="http://dev.virtualearth.net/REST/V1/Routes?
  wp.0={0}&wp.1={1}&output=xml&key={2}&optimize={3}";
 
 string homeAddress;
 
 string workAddress;
 
 string fullUri;
 
 const string bingKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

 fullUri = String.Format(bingUri,homeAddress,workAddress,bingKey,"time" );
 
 WebClient proxy = new WebClient();
 
 proxy.OpenReadCompleted += 
     new OpenReadCompletedEventHandler(proxy_OpenReadCompleted);
 
 proxy.OpenReadAsync(new Uri(fullUri));

proxy_OpenReadCompleted looks like this: (The following code also extracts traffic information)

uction = instruction; this.warnings = warnings; } } public class Warning { public string severity; public string desc; public Warning(string severity, string desc) { this.severity = severity; this.desc = desc; } }

If you want to loop through the results use this model:

foreach (ItineraryItem itineraryItem in itineraryItems)
{
  foreach (Warning warning in itineraryItem.warnings)
  {
                  
  }
}

You can find more options for REST API here: http://msdn.microsoft.com/en-us/library/ff701722.aspx

blog comments powered by Disqus