如何在折线上显示持续时间弹出窗口?

3

我想在Polyline上显示路线持续时间,如屏幕截图所示。我在互联网上进行了一些搜索,但没有找到解决方案。

screenshot

如果你有任何解决方案,请指导我。 谢谢。


请参考以下链接:https://developers.google.com/maps/documentation/android-api/shapes - Ravindra Kushwaha
请简要说明细节。这些对话框/弹出窗口没有任何信息。 - activesince93
请参考以下内容:https://dev59.com/2HbZa4cB1Zd3GeqPJsaz - Chirag Savsani
此外,这个链接可能会有所帮助:https://developers.google.com/maps/documentation/directions/?csw=1 - Chirag Savsani
2个回答

0
使用Google Direction API获取路线并绘制折线。
在地图中添加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);

在折线点击中打开弹出窗口

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;
        }
    });
}

0

信息窗口始终锚定在标记上。我想将其锚定到“折线”。 - activesince93
如果您想在折线中添加图像,可以使用符号。符号是通过使用SVG路径符号定义的基于矢量的图像。要将符号添加到折线中,请设置PolylineOptions对象的icons[]属性。这个链接也可能会有所帮助。 - abielita

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接