Reputation: 1092
I want to draw a path between two locations using on android google map.I have tired this code
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
if (cursor.moveToFirst()) {
do {
// latitude and longitude
double latitude = 0.00;
double longitude = 0.00;
Log.i("lat", cursor.getString(10));
Log.i("lat", cursor.getString(11));
try {
latitude = Double.parseDouble(cursor.getString(10));
} catch (Exception e) {
}
try {
longitude = Double.parseDouble(cursor.getString(11));
} catch (Exception e) {
}
if (latitude == 0.00 || longitude == 0.00) {
} else {
i++;
LatLng point = new LatLng(latitude,longitude);
options.add(point);
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title(cursor.getString(1));
}
}
while (cursor.moveToNext());
}
cursor.close();
googleMap.addPolyline(options);
but i got straight line.like this
I want to get paths on actual roads.
Thanks..!!
Upvotes: 3
Views: 316
Reputation: 6703
If you want to draw a polyline between 2 points and following road, you can try with the library Google-Directions-Android
You can add the library on gradle with compile 'com.github.jd-alexander:library:1.0.7'
You can use all your point (Latlng) and use them into the waypoint method.
Routing routing = new Routing.Builder()
.travelMode(/* Travel Mode */)
.withListener(/* Listener that delivers routing results.*/)
.waypoints(/*waypoints*/)
.build();
routing.execute();
Upvotes: 1