在google maps api V2中创建自定义标记菜单

时间:2014-07-04 17:24:33

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

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

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

1 个答案:

答案 0 :(得分:1)

您可以使用适配器自定义弹出窗口,只需调用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界面的文档。