Android 集成google地圖title無法顯示的問題

一 在國內或許大家都在集成的是百度或者高德地圖,但是若是你做的是國外或者是香港需要集成地圖功能的可能會首先選擇google吧。最近在修改一個香港的項目但是在地圖上添加了marker之後,title想一直顯示,但是就是出不來,糾結了好久終於發現問題,以下是解決方式:

        if (MyApplication.markers != null) 
        {   
            /**
             * 獲取保存的地址信息
             */
            LatLng latLng = new LatLng(MyApplication.markers.getPosition().latitude,MyApplication.markers.getPosition().longitude);
            /**
             * 添加標記
             */
            final Marker smarker = googleMap.addMarker(new MarkerOptions()
                                    .title(MyApplication.markers.getTitle()).visible(true)
                                    .position(latLng)
                                    .icon(BitmapDescriptorFactory.defaultMarker())
                    );
            CameraUpdate lUpdate = CameraUpdateFactory.newLatLngZoom(latLng,(float)16);
            /**
             * 讓地圖目前的視圖停留在標記位置
             */
            googleMap.moveCamera(lUpdate);
            /**
             * 1.這裏是最關鍵的一點
             * 2.這裏需要更新UI線程,因此使用handler的post方法
             * 3.在post方法中調用showInfoWindow()纔會生效
             */
            handler.post(new Runnable() {
                @Override
                public void run() {
                    smarker.showInfoWindow();
                }
            });
            /**
             * 保存的標記信息進行初始化
             */
            MyApplication.markers = null;
        }

二 推薦幾篇比較好的國外解決方法鏈接:

marker.showInfoWindow() has no effect using google map API V2 Lite Mode

Opening InfoWindow automatically when adding marker Google Maps v2 Android

Issue 5115: Bug: Cannot call Marker.showInfoWindow immediately after GoogleMap.addMarker()

謝謝

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章