draw polyline on roads in android

Home / Uncategorized / draw polyline on roads in android

Question:
I currently have a google map in my android app with user location marker on open map and when user click to a position in map a blue marker will shows(destination marker) with a polyline between user location marker and destination marker like this image:

How can i draw this lines in roads ???
I have following code :@Override
public void onMapReady(final GoogleMap googleMap) {
this.googleMap = googleMap;
googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
destinationLocation = new Location(LocationManager.GPS_PROVIDER);
destinationLocation.setLatitude(latLng.latitude);
destinationLocation.setLongitude(latLng.longitude);
destinationMarker = googleMap.addMarker(new MarkerOptions().position(latLng).title("your destination").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_destination_marker)));
Polyline line = googleMap.addPolyline(new PolylineOptions()
.add(new LatLng(userLocation.getLatitude(),
userLocation.getLongitude()), new LatLng(destinationLocation.getLatitude(),
destinationLocation.getLongitude())).color(Color.BLUE).width(10));
}
});
}


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *