您的位置:首页 > 移动开发 > Android开发

Android 集成google地图title无法显示的问题

2015-09-06 14:43 645 查看
一 在国内或许大家都在集成的是百度或者高德地图,但是若是你做的是国外或者是香港需要集成地图功能的可能会首先选择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()

谢谢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: