使用jQuery Mobile使用xml数据对距离进行排序

使用jQuery Mobile使用xml数据对距离进行排序,jquery,sorting,jquery-mobile,xml-parsing,cordova,Jquery,Sorting,Jquery Mobile,Xml Parsing,Cordova,我有以下xml数据: 我得到的JSON响应如下: 在回答中,我得到了距离,例如9.4公里。我想根据这个距离对xml进行排序。与当前位置最近的5个站点类似 我应该如何处理这个问题?我能想到的是: 使用jQuery解析xml。 然后查询每对当前位置和目的站的Google距离矩阵API以获得距离。 将每个桩号的结果存储在关联数组中,并动态创建关键点以供参考。 最后对关联数组进行排序。 完成所有这些之后,我应该能够使用站点名称、计算的距离以及与已排序站点关联的url 我通常考虑的解决方案,特别是关于关联

我有以下xml数据:

我得到的JSON响应如下:

在回答中,我得到了距离,例如9.4公里。我想根据这个距离对xml进行排序。与当前位置最近的5个站点类似

我应该如何处理这个问题?我能想到的是:

使用jQuery解析xml。 然后查询每对当前位置和目的站的Google距离矩阵API以获得距离。 将每个桩号的结果存储在关联数组中,并动态创建关键点以供参考。 最后对关联数组进行排序。 完成所有这些之后,我应该能够使用站点名称、计算的距离以及与已排序站点关联的url

我通常考虑的解决方案,特别是关于关联数组的键的动态生成的解决方案是好的吗?如果有人能告诉我如何做,我将非常感激。也许有些代码会更好

<nextbus>
<station>
    <name>Resecentrum</name>
    <url>http://wap.nastabuss.se/its4wap/QueryForm.aspx?hpl=Resecentrum+(V%C3%A4xj%C3%B6)</url>
    <latitude>56.87900440</latitude>
    <longitude>14.80585220</longitude>
</station>
<station>
    <name>Lunnabyvägen</name>
    <url>http://wap.nastabuss.se/its4wap/QueryForm.aspx?hpl=Lunnabyv%C3%A4gen+(V%C3%A4xj%C3%B6)</url>
    <latitude>56.9127830</latitude>
    <longitude>14.74299680</longitude>
</station>
<station>
    <name>Slottsruinen</name>
    <localurl>http://crossplatform.co.nf/sample%20html/Slottsruinen+(V%C3%A4xj%C3%B6).html</localurl>
    <latitude>56.9387270</latitude>
    <longitude>14.79787070</longitude>
</station>
<station>
    <name>Evedal</name>
    <localurl>http://crossplatform.co.nf/sample%20html/Evedal+(V%C3%A4xj%C3%B6).html</localurl>
    <latitude>56.92177890000001</latitude>
    <longitude>14.82015180</longitude>
</station>

.....
http://maps.googleapis.com/maps/api/distancematrix/json?origins=56.8517837,14.8284759&destinations=56.91869459999999,14.85939390&mode=walking&sensor=false
 {
   "destination_addresses" : [ "Lenhovdavägen 60, 352 49 Växjö Municipality, Sweden" ],
   "origin_addresses" : [ "Tuvanäsvägen 1, Linnéuniversitetet, 352 52 Växjö, Sweden" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "9.4 km",
                  "value" : 9429
               },
               "duration" : {
                  "text" : "1 hour 57 mins",
                  "value" : 7010
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}