答案 0 :(得分:0)
您可以根据位置显示标记,标记有自己的信息窗口 请参阅此链接 https://developers.google.com/maps/documentation/android-api/infowindows
答案 1 :(得分:0)
使用Google Direction API获取路线并绘制折线
在Map中添加OnPolylineClickListener并使用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 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;
}
});
}