Reputation: 2016
I am using the Bing Maps Api to calculate the route between two points. I use the Rest Services in combination with the RestSharp library. Problem is that I don't know how I can access the Route results.
The results are of type Resource. Route derives of Resource. The Resource class is decorated with the KnownType attribute. FYI I use the JSON datacontracts from msdn
Can someone help me?
Here is my code to calculate the route:
public static double CalculateDistanceKm(string street, string postalCode, string city, string country)
{
var client = new RestClient(BingMapsApiUrl);
var request = new RestRequest("Routes/Driving", Method.GET);
request.AddParameter("wp.0", Address);
request.AddParameter("wp.1", String.Format("{0},{1} {2},{3}", street, postalCode, city, country));
request.AddParameter("ul", "50.7541313,4.2486601");
request.AddParameter("key", BingMapsApiKey);
var response = client.Execute(request);
if (response.ResponseStatus == ResponseStatus.Completed)
{
var result = JsonConvert.DeserializeObject<Response>(response.Content);
if (result != null && result.StatusCode == 200 & result.ResourceSets.Any() && result.ResourceSets[0].Resources.Any())
{
//How to get to the Route instead of just Resource...
var test = result.ResourceSets.First().Resources.First();
}
}
return 0;
}
Upvotes: 0
Views: 569
Reputation: 2016
I switched the api from Bing to Google Maps. The api is a lot easier to use and it gave me the right results.
With Bing I had a 9/10 change to get a "Not_found" error, tested with the SAME address! So sometimes it works (1/10 chance). With Google I get a correct result on each try...
Don't make the same mistake as I did, if you want to lookup address in another language than english then use Google Maps API.
Upvotes: 0