0
votes

I used Google direction API and received data as a json file. My url is like

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

and I used optimized:true parameter. As I read it gives me optimal path from source to destination through the waypoints. And now i dont know structure of json file exactly. I look up the structure of json file but i don t know how can i take order of path that Google direction API gives me.

3
You havent marked any questions as answered. Ever. Fix that with your old ones and people will be more willing to help youEric

3 Answers

0
votes

I was also trying to use the Direction Api of Google in Android. So I made an open source project to help doing that. You can find it here:https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils

How it works, definitly simply:

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);
    }
}
0
votes

The call which you mentioned will give the optimal route that you should follow. In order to know what the route is you need to see the value for waypoint_order.

For your call, the waypoint order is: "waypoint_order" : [ 3, 2, 0, 1 ]

So, the optimal result would be that you need to visit the waypoints in the order: Origin - 3 - 2 - 0 - 1 - Destination.

In your case it would be: Adelaide,SA - McLaren Vale,SA - Connawarra,SA - Barossa Valley,SA - Clare,SA - Adelaide,SA

for your call: 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