简体   繁体   English

Google Maps Android V2:如何平移地图以显示InfoWindow

[英]Google maps android V2: how to pan map to show InfoWindow

I have a map with custom Infowindow and I'd like to make sure that every time a user clicks a marker the info window will be fully visible, how can i do that? 我有一个带有自定义Infowindow的地图,我想确保每次用户单击标记时,信息窗口将完全可见,我该怎么做?

I already have some code to prevent centering on clicked marker but i have no idea how to do what i need: 我已经有一些代码来防止以单击标记为中心,但是我不知道如何做我需要做的事情:

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

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

The "default behavior" that you are blocking by returning true is to show the info window, and then center the map on the marker. 通过返回true阻止的“默认行为”是显示信息窗口,然后将地图居中在标记上。

I think if you don't call marker.showInfoWindow() , and return false you'll get what you want. 我认为,如果不调用marker.showInfoWindow()并返回false ,则会得到想要的结果。

If what you want is to pan the map just enough to show the info window, then you have to do those calculations yourself and pan the map with a CameraUpdateFactory . 如果要平移地图以显示信息窗口,则必须自己进行计算,然后使用CameraUpdateFactory平移地图。 CameraUpdateFactory.scrollBy() or something like that. CameraUpdateFactory.scrollBy()或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM