关于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; }
}
}
希望这有助于:)