在Android谷歌地图v2中打开自定义信息窗口

时间:2014-09-09 10:49:26

标签: android google-maps google-maps-markers google-maps-android-api-2

我正在尝试打开自定义InfoWindows(使用InfoWindowAdapter)默认情况下。我的意思是在加载地图后立即。这可能吗?如果是这样的话?

我有以下内容:

googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
    final Marker mark = googleMap.addMarker(new MarkerOptions().position(latLong)
                    .title("Last Updated:"));
        markers.put(mark.getId(), url);

我的自定义信息窗口适配器

private class CustomInfoWindowAdapter implements InfoWindowAdapter
{

    private View view;

    public CustomInfoWindowAdapter() {
        view = getLayoutInflater().inflate(R.layout.custom_info_window,
                null);
    }

    @Override
    public View getInfoContents(Marker marker) {

        if (MainActivity.this.marker != null
                && MainActivity.this.marker.isInfoWindowShown()) {
            MainActivity.this.marker.hideInfoWindow();
            MainActivity.this.marker.showInfoWindow();
        }
        return null;
    }

    @Override
    public View getInfoWindow(final Marker marker) 
    {
        MainActivity.this.marker = marker;

        String url = null;

        if (marker.getId() != null && markers != null && markers.size() > 0) {
            if ( markers.get(marker.getId()) != null &&
                    markers.get(marker.getId()) != null) {
                url = markers.get(marker.getId());
            }
        }
        final ImageView image = ((ImageView) view.findViewById(R.id.badge));

        if (url != null && !url.equalsIgnoreCase("null")
                && !url.equalsIgnoreCase("")) {
            imageLoader.displayImage(url, image, options,
                    new SimpleImageLoadingListener() {
                        @Override
                        public void onLoadingComplete(String imageUri,
                                View view, Bitmap loadedImage) {
                            super.onLoadingComplete(imageUri, view,
                                    loadedImage);
                            getInfoContents(marker);
                        }
                    });
        } else {
            image.setImageResource(R.drawable.ic_launcher);
        }

        final String title = marker.getTitle();
        final TextView titleUi = ((TextView) view.findViewById(R.id.title));
        if (title != null) {
            titleUi.setText(title);
        } else {
            titleUi.setText("");
        }

        final String snippet = marker.getSnippet();
        final TextView snippetUi = ((TextView) view
                .findViewById(R.id.snippet));
        if (snippet != null) {
            snippetUi.setText(snippet);
        } else {
            snippetUi.setText("");
        }

        return view;
    }
}

上面显示了一个图钉,我点击了解窗口信息。我想自动显示自定义信息窗口。

感谢!

1 个答案:

答案 0 :(得分:1)

markers.showInfoWindow();

For more detail go through the link