【问题标题】:Google direction API json file parsing谷歌方向API json文件解析
【发布时间】:2011-09-23 00:12:25
【问题描述】:

我使用 Google Direction API 并以 json 文件的形式接收数据。我的网址就像

http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&sensor=false

我使用了 optimize:true 参数。当我读到它时,它为我提供了通过航点从源头到目的地的最佳路径。现在我不确切知道 json 文件的结构。我查找了 json 文件的结构,但我不知道如何按照 Google 方向 API 给我的路径顺序。

【问题讨论】:

  • 您尚未将任何问题标记为已回答。曾经。用你的旧人解决这个问题,人们会更愿意帮助你

标签: android json mobile google-maps-api-3 google-api


【解决方案1】:
【解决方案2】:

我还尝试在 Android 中使用 Google 的 Direction Api。 所以我做了一个开源项目来帮助做到这一点。 你可以在这里找到它:https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils

它是如何工作的,绝对简单:

public class MainActivity extends ActionBarActivity implements DCACallBack{
/**
 * Get the Google Direction between mDevice location and the touched location using the     Walk
 * @param point
 */
private void getDirections(LatLng point) {
     GDirectionsApiUtils.getDirection(this, mDeviceLatlong, point,     GDirectionsApiUtils.MODE_WALKING);
}

/*
 * The callback
 * When the direction is built from the google server and parsed, this method is called and give you the expected direction
 */
@Override
public void onDirectionLoaded(List<GDirection> directions) {        
    // Display the direction or use the DirectionsApiUtils
    for(GDirection direction:directions) {
        Log.e("MainActivity", "onDirectionLoaded : Draw GDirections Called with path " + directions);
        GDirectionsApiUtils.drawGDirection(direction, mMap);
    }
}

【讨论】:

    【解决方案3】:

    您提到的呼叫将提供您应该遵循的最佳路线。为了知道路线是什么,您需要查看 waypoint_order 的值。

    对于您的呼叫,航点顺序为: "waypoint_order" : [ 3, 2, 0, 1 ]

    因此,最佳结果是您需要按以下顺序访问航点:起点 - 3 - 2 - 0 - 1 - 目的地。

    在您的情况下,它将是: 南澳州阿德莱德 - 南澳州麦克拉伦谷 - 南澳州康纳瓦拉 - 南澳州巴罗萨谷 - 南澳州克莱尔 - 南澳州阿德莱德

    您的电话: http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&sensor=false

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多