關於Google Map - 距離矩陣API。結果是否會保證在同一個訂單中有要求? 如果我要求API獲取從一個起始點到多個目標點的距離,結果排序是否能保證與請求的順序相匹配?Google Map - 距離矩陣API - 結果順序
我需要將我的業務對象映射到API調用的結果,我找不到硬映射他們。只有訂單縫適合。
感謝您的輸入。
雨果
關於Google Map - 距離矩陣API。結果是否會保證在同一個訂單中有要求? 如果我要求API獲取從一個起始點到多個目標點的距離,結果排序是否能保證與請求的順序相匹配?Google Map - 距離矩陣API - 結果順序
我需要將我的業務對象映射到API調用的結果,我找不到硬映射他們。只有訂單縫適合。
感謝您的輸入。
雨果
距離矩陣API的Web服務返回結果作爲rows
陣列,其中每一行項目對應於一個來源從origins
參數在請求和所述順序被保存在原始請求。每個行項目包含elements
數組,其中每個元素對應於請求中參數destinations
中的一個目標,並且順序也被保留。
你可以看看官方文檔在距離矩陣API響應結構進行了說明:
https://developers.google.com/maps/documentation/distance-matrix/intro#DistanceMatrixResponses
希望這有助於!
1)結果如果是JSON響應,它將採用相同的格式。 實施例:a.Single響應:
{
"destination_addresses": [
"Karnataka, India"
],
"origin_addresses": [
"Delhi, India"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "1,942 km",
"value": 1941907
},
"duration": {
"text": "1 day 9 hours",
"value": 120420
},
"status": "OK"
}
]
}
],
"status": "OK"
}
灣多重響應:
{
"destination_addresses": [
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"67-89 Pacific St, Brooklyn, NY 11201, USA",
"557-599 Dr Wesley McDonald Ave, Brooklyn, NY 11203, USA",
"66-0-66-26 103rd St, Rego Park, NY 11374, USA",
"1000 N Village Ave, Rockville Centre, NY 11570, USA",
"300-448 Beach 19th St, Far Rockaway, NY 11691, USA",
"557-599 Dr Wesley McDonald Ave, Brooklyn, NY 11203, USA",
"66-0-66-26 103rd St, Rego Park, NY 11374, USA",
"1000 N Village Ave, Rockville Centre, NY 11570, USA",
"300-448 Beach 19th St, Far Rockaway, NY 11691, USA"
],
"origin_addresses": [
"566 Vermont St, Brooklyn, NY 11207, USA"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2096
},
"status": "OK"
},
{
"distance": {
"text": "2.9 mi",
"value": 4662
},
"duration": {
"text": "18 mins",
"value": 1086
},
"status": "OK"
},
{
"distance": {
"text": "8.5 mi",
"value": 13738
},
"duration": {
"text": "23 mins",
"value": 1367
},
"status": "OK"
},
{
"distance": {
"text": "15.9 mi",
"value": 25544
},
"duration": {
"text": "29 mins",
"value": 1755
},
"status": "OK"
},
{
"distance": {
"text": "13.2 mi",
"value": 21296
},
"duration": {
"text": "34 mins",
"value": 2058
},
"status": "OK"
},
{
"distance": {
"text": "2.9 mi",
"value": 4662
},
"duration": {
"text": "18 mins",
"value": 1086
},
"status": "OK"
},
{
"distance": {
"text": "8.5 mi",
"value": 13738
},
"duration": {
"text": "23 mins",
"value": 1367
},
"status": "OK"
},
{
"distance": {
"text": "15.9 mi",
"value": 25544
},
"duration": {
"text": "29 mins",
"value": 1755
},
"status": "OK"
},
{
"distance": {
"text": "13.2 mi",
"value": 21296
},
"duration": {
"text": "34 mins",
"value": 2058
},
"status": "OK"
}
]
}
],
"status": "OK"
}
2)我認爲上面的例子應該照顧第二個問題。
3)同.NET對象的結果JSON可以容易地mapped.Here在下面映射類
public class Response
{
public string Status { get; set; }
[JsonProperty(PropertyName = "destination_addresses")]
public string[] DestinationAddresses { get; set; }
[JsonProperty(PropertyName = "origin_addresses")]
public string[] OriginAddresses { get; set; }
public Row[] Rows { get; set; }
public class Data
{
public int Value { get; set; }
public string Text { get; set; }
}
public class Element
{
public string Status { get; set; }
public Data Duration { get; set; }
public Data Distance { get; set; }
}
public class Row
{
public Element[] Elements { get; set; }
}
}
希望這有助於:)