J’essaie d’obtenir la direction de conduite entre les deux positions:
LatLng(12.917745600000000000,77.623788300000000000) LatLng(12.842056800000000000,7.663096499999940000)
Le code que j’ai essayé:
Polyline line = mMap.addPolyline(new PolylineOptions(). add(new LatLng(12.917745600000000000,77.623788300000000000), new LatLng(12.842056800000000000,7.663096499999940000)) .width(5).color(Color.RED));
Mais cela trace une ligne droite entre les deux points.
Existe-t-il une autre méthode / manière d’obtenir les itinéraires entre ces deux points?
Je viens de publier ma dernière bibliothèque pour Google Maps Direction API sur Android https://github.com/akexorcist/Android-GoogleDirectionLibrary
C’est ce que j’utilise,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER ); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent);
Vous pouvez également essayer le projet suivant qui vise à aider à utiliser cette API. C’est ici: https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils
Comment ça marche, tout simplement:
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 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); } }