Skip to content
MathiasSeguy-Android2EE edited this page Sep 14, 2013 · 13 revisions

Your Goal: You already have an application that uses GoogleMap and you want to display Directions on it. In that case, find the jar bin\gdirectionsapiutils.jar and copy/paste it in the libs folder of your project. And that's it.
Your Goal: You want to modify or understand the GDirectionApiUtils to use it. You need to install the project in your workspace and link it to your project. Your installation:

//Download the project, import it in Eclipse.
//Doesn't compile.
try{
//Ok, this project needs to know the GoogleMap object embedded in the GooglePlayService Api. 
//So as you did for your own project link google play service to this project.
}catch(InstallException){
//1)Import the google_play_service
//In Eclipse, do new\other\AndroidProject... then select $user\androidsdk\extras\google\libproject\google_play_service_lib
//Compile this new project 
//2)Link it to the GDirectionsApiUtils
//GDirectionsApiUtils->BuildPath, Select Android and then add the google_play_service_lib as a librairy
}
finally{//compile GDirectionsApiUtils.}

In your own Project, import it as a librairy, copy/paste the gdirectionsapiutils.jar from GDirectionsApiUtils/bin/ to your libs project. And that's all.

Ok, compile, and then use it to retrieve direction between two points. First ask for the direction using getDirection and then when the stuff is built, we call the method onDirectionLoaded giving you the Directions your were looking for:


	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);
	}/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.android2ee.formation.librairies.google.map.direction.DCACallBack#onDirectionLoaded(com
	 * .android2ee.formation.librairies.google.map.direction.GDirection)
	 */
	@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);
		}
	}`
Clone this wiki locally