Back to project page Google-Directions-Android.
The source code is released under:
Copyright (c) 2013 Joel Dean Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software...
If you think the Android project Google-Directions-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.directions.android; //w w w . ja va 2 s . co m import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.directions.route.Routing; import com.directions.route.RoutingListener; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.PolylineOptions; public class MyActivity extends FragmentActivity implements RoutingListener { protected GoogleMap map; protected LatLng start; protected LatLng end; /** * This activity loads a map and then displays the route and pushpins on it. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); map = fm.getMap(); CameraUpdate center=CameraUpdateFactory.newLatLng(new LatLng(18.013610,-77.498803)); CameraUpdate zoom= CameraUpdateFactory.zoomTo(15); map.moveCamera(center); map.animateCamera(zoom); start = new LatLng(18.015365, -77.499382); end = new LatLng(18.012590, -77.500659); Routing routing = new Routing(Routing.TravelMode.WALKING); routing.registerListener(this); routing.execute(start, end); } @Override public void onRoutingFailure() { // The Routing request failed } @Override public void onRoutingStart() { // The Routing Request starts } @Override public void onRoutingSuccess(PolylineOptions mPolyOptions) { PolylineOptions polyoptions = new PolylineOptions(); polyoptions.color(Color.BLUE); polyoptions.width(10); polyoptions.addAll(mPolyOptions.getPoints()); map.addPolyline(polyoptions); // Start marker MarkerOptions options = new MarkerOptions(); options.position(start); options.icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue)); map.addMarker(options); // End marker options = new MarkerOptions(); options.position(end); options.icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green)); map.addMarker(options); } }