0
我使用Bing Maps Api來計算兩點之間的路線。 我將Rest Services與RestSharp庫結合使用。 問題是我不知道如何訪問路線結果。Bing Maps Api:Deserialise Json結果
結果屬於Resource類型。資源的路線派生。 Resource類使用KnownType屬性進行裝飾。 僅供參考我使用JSON數據合同msdn
有人可以幫助我嗎?
這裏是我的代碼來計算路線:
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;
}
嘗試新的Bing Maps v8,好多了 – juFo