I want to show route duration on Polyline
as shown on the screenshot. I have done some digging on internet but couldn't find the solution.
Guide me if anyone of you have any solution. Thanks.
I want to show route duration on Polyline
as shown on the screenshot. I have done some digging on internet but couldn't find the solution.
Guide me if anyone of you have any solution. Thanks.
you can show markers according to locations and markers have their own info windows refer to this link https://developers.google.com/maps/documentation/android-api/infowindows
Use Google Direction API to get the route and draw the polyline
Add OnPolylineClickListener in Map and get the reference using getTag
mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
@Override
public void onPolylineClick(Polyline polyline) {
Log.e("Polyline position", " -- " + polyline.getTag());
onButtonShowPopupWindowClick(" " + polyline.getTag());
}
});
Set any reference in polyline using setTag method
Polyline line = mMap.addPolyline(lineOptions);
line.setTag("" + i);
line.setClickable(true);
Open PopupWindow in polyline click
public void onButtonShowPopupWindowClick(String count) {
String[] timeDistance = count.split(",");
// get a reference to the already created main layout
LinearLayout mainLayout = (LinearLayout)
findViewById(R.id.whole_layout);
// inflate the layout of the popup window
LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.polyline_window, null);
((TextView) popupView.findViewById(R.id.time)).setText("30 mins");
((TextView) popupView.findViewById(R.id.distance)).setText("20 km");
// create the popup window
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; // lets taps outside the popup also dismiss it
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
// show the popup window
popupWindow.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
// dismiss the popup window when touched
popupView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return true;
}
});
}