Ответ 1
Я только что выпустил свою последнюю библиотеку для Google Maps Direction API на Android https://github.com/akexorcist/Android-GoogleDirectionLibrary
Я пытаюсь получить направление движения между двумя позициями:
LatLng(12.917745600000000000,77.623788300000000000)
LatLng(12.842056800000000000,7.663096499999940000)
Код, который я пробовал:
Polyline line = mMap.addPolyline(new PolylineOptions().
add(new LatLng(12.917745600000000000,77.623788300000000000),
new LatLng(12.842056800000000000,7.663096499999940000))
.width(5).color(Color.RED));
Но это рисует прямую линию между двумя точками.
Есть ли другой способ/способ получить маршруты проезда между этими двумя точками.
Я только что выпустил свою последнюю библиотеку для Google Maps Direction API на Android https://github.com/akexorcist/Android-GoogleDirectionLibrary
Это то, что я использую,
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);
Вы также можете попробовать следующий проект, целью которого является использование этого 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);
}
}