Android Google Map v2 draw a route
I have a Google Map fragment:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="my.package.MapsActivity"
android:layout_marginTop="?actionBarSize"/>
I get my location like this:
private void getMyLocation() {
LatLng latLng = new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 16);
mMap.animateCamera(cameraUpdate);
}
You need to show the route to the specified coordinates, as in the photo:
3
Author: Roman Svyatnenko, 2015-11-29
2 answers
This library helped. My code:
Route supportRoute = new Route();
LatLng source = new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude());
LatLng dest= new LatLng(destLat, destLog);
supportRoute.drawRoute(mMap, MapsActivity.this, source, dest, true, "en");
3
Author: Roman Svyatnenko, 2015-12-01 01:23:57
As an option, use the library Google-Directions-Android
1
Author: Dan, 2015-11-30 19:06:05