java - 谷歌地图 Android V2 : how to pan map to show InfoWindow

标签 java android google-maps

我有一张带有自定义信息窗口的 map ,我想确保每次用户单击标记时信息窗口都完全可见,我该怎么做?

我已经有一些代码来防止以单击的标记为中心,但我不知道如何执行我需要的操作:

private void preventMarkerCenter(){
        map.setOnMarkerClickListener(new OnMarkerClickListener() {
        public boolean onMarkerClick(Marker marker) {
            // Check if there is an open info window
            if (lastOpenned != null) {
                // Close the info window
                lastOpenned.hideInfoWindow();

                // Is the marker the same marker that was already open
                if (lastOpenned.equals(marker)) {
                    // Nullify the lastOpenned object
                    lastOpenned = null;
                    // Return so that the info window isn't openned again
                    return true;
                } 
            }

            // Open the info window for the marker
            marker.showInfoWindow();
            // Re-assign the last openned such that we can close it later
            lastOpenned = marker;

            // Event was handled by our code do not launch default behaviour.
            return true;
        }
        });
    }

最佳答案

根据文档:http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.OnMarkerClickListener.html

您通过返回 true 阻止的“默认行为”是显示信息窗口,然后将 map 置于标记的中心。

我想如果你不调用marker.showInfoWindow(),并返回false,你就会得到你想要的。

如果您想要平移 map 刚好足以显示信息窗口,那么您必须自己进行这些计算并使用 CameraUpdateFactory 平移 map 。CameraUpdateFactory.scrollBy( ) 或类似的东西。

关于java - 谷歌地图 Android V2 : how to pan map to show InfoWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19799817/

相关文章:

android - Gradle 同步失败 : Could not find method compile() for arguments [com. android.support :appcompat-v7:25. 3.1]

ruby-on-rails - 将 Google Maps (API V3) 支持添加到 Ruby on Rails 应用程序

java - Tomcat 应用程序显示 "Unable to configure the logging system. No log.properties was found."

java - OpenGL 2D 碰撞检测不起作用

android - ListView 中的 TextView 在滚动时发生变化

android - Cordova 地理定位插件无法从适用于 Android 的 GPS 获取位置

javascript - Google map 和 jQuery 错误消息 - 地理定位

google-maps - Google Maps Geocoding API 区域与组件 :country parameters? 之间有什么区别

Java循环收集数组中每三个元素的第二个和第三个元素

java - 它必须是 StackoverflowError 或 OOME