谷歌距离马蒂克斯按距离排序

时间:2017-08-07 13:11:59

标签: google-maps google-maps-api-3

当我从https://maps.googleapis.com/maps/api/distancematrix/json?origins=10010&destinations=10011|10012|10013&key=AIzaSyBOsjeskUwOLYQZntsv7_34gVZ3xgcXko0

获取数据时

它返回:

{
   "destination_addresses" : [
      "New York, NY 10011, USA",
      "New York, NY 10012, USA",
      "New York, NY 10013, USA"
   ],
   "origin_addresses" : [ "New York, NY 10010, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "3.4 km",
                  "value" : 3389
               },
               "duration" : {
                  "text" : "19 mins",
                  "value" : 1156
               },
               "status" : "OK"
            },
            {
               "distance" : {
                  "text" : "2.6 km",
                  "value" : 2632
               },
               "duration" : {
                  "text" : "13 mins",
                  "value" : 767
               },
               "status" : "OK"
            },
            {
               "distance" : {
                  "text" : "9.5 km",
                  "value" : 9545
               },
               "duration" : {
                  "text" : "19 mins",
                  "value" : 1143
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

但我需要按距离排序数据。首先显示小而大。

有可能吗?

1 个答案:

答案 0 :(得分:0)

当然!  1.将JSON数据解析为对象(JSON.parse);  2.使用如下代码对元素数组进行排序:

matplotlib.animation.FuncAnimation