API Google Direction
OnPolylineClickListener Map getTag
mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
@Override
public void onPolylineClick(Polyline polyline) {
Log.e("Polyline position", " -- " + polyline.getTag());
onButtonShowPopupWindowClick(" " + polyline.getTag());
}
});
setTag
Polyline line = mMap.addPolyline(lineOptions);
line.setTag("" + i);
line.setClickable(true);
PopupWindow
public void onButtonShowPopupWindowClick ( ) {
String[] timeDistance = count.split(",");
LinearLayout mainLayout = (LinearLayout)
findViewById(R.id.whole_layout);
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");
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true;
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
popupWindow.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
popupView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return true;
}
});
}