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

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

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

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

最佳答案

您可以使用 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 的文档界面。

关于android - 在 google maps api V2 中创建自定义标记菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24578762/

相关文章:

Android Studio 方法分隔符

android - Android、Windows Phone 7 和 Blackberry 的等效配置文件 (iOS)

jquery - 优化 jQueryMobile : problems with selectively including external JS files only when they are needed 代码

php - 如何使用 jquery-ui-map 在谷歌地图上添加标记

android - 防止 Android 软键盘在 fragment 中向上移动 View ?

android - 当我从 SQLite 中检索 blob 值时,它会给出不同的值,因为它存储在数据库中

java - 不同dpi的径向渐变

ios - 我试图在覆盖 func tableView(...didSelectRowAt...) 时关闭我的 tableViewController,但没有任何反应

ios - RestKit RKObjectMapping.. 嵌套和一次性对象

ios - 谷歌地图标记在 map 中间加载