1

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

我已经有一些代码可以防止以单击的标记为中心,但我不知道如何做我需要的事情:

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

1 回答 1

0

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

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

我想如果你不打电话marker.showInfoWindow(),然后回来,false你会得到你想要的。

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

于 2014-01-27T22:20:34.373 回答