簡體   English   中英

Google Maps Android V2:如何平移地圖以顯示InfoWindow

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

我有一個帶有自定義Infowindow的地圖,我想確保每次用戶單擊標記時,信息窗口將完全可見,我該怎么做?

我已經有一些代碼來防止以單擊標記為中心,但是我不知道如何做我需要做的事情:

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阻止的“默認行為”是顯示信息窗口,然后將地圖居中在標記上。

我認為,如果不調用marker.showInfoWindow()並返回false ,則會得到想要的結果。

如果要平移地圖以顯示信息窗口,則必須自己進行計算,然后使用CameraUpdateFactory平移地圖。 CameraUpdateFactory.scrollBy()或類似的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM