【问题标题】:Creating a custom marker menu in google maps api V2在谷歌地图 api V2 中创建自定义标记菜单
【发布时间】:2014-07-04 17:24:33
【问题描述】:

我正在尝试创建一个类似于 Waze 的应用,但我不知道如何为标记制作弹出菜单 喜欢this

我正在尝试做的系统是,如果用户决定标记他们当前的位置或双击地图上的任何位置,则会弹出一个菜单,其中包含我自己的标记选择。 我正在使用适用于 Android 和 iOS 的最新版 Google 地图

【问题讨论】:

    标签: android ios google-maps-markers google-maps-android-api-2


    【解决方案1】:

    您可以使用Adapter自定义弹出窗口,只需调用setInfoWindowAdapter方法并覆盖以下方法,如下所示:

    mGoogleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
                @Override
                public View getInfoWindow(Marker arg0) {
                    return null;
                }
    
                @Override
                public View getInfoContents(Marker marker) {
                    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View rowView = inflater.inflate(R.layout.item_marker_location, null);
                    TextView tvTitle   = (TextView) rowView.findViewById(R.id.tvMarkerTitle);
                    TextView tvSnippet = (TextView) rowView.findViewById(R.id.tvMarkerSnippet);
                    tvTitle.setText(marker.getTitle());
                    tvSnippet.setText(marker.getSnippet());
                    return rowView;
                }
            });
    

    您可以阅读InfoWindowAdapter接口的文档。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    相关资源
    最近更新 更多