【问题标题】:Dynamic contents in Maps V2 InfoWindowMaps V2 InfoWindow 中的动态内容
【发布时间】:2013-03-08 08:24:24
【问题描述】:

我想在 Maps V2 片段中的标记上显示信息窗口。 问题是,我想显示从网络动态加载的位图 Universal Image Downloader

这是我的 InfoWindowAdapter:

class MyInfoWindowAdapter implements InfoWindowAdapter {

    private final View v;

    MyInfoWindowAdapter() {
        v = getLayoutInflater().inflate(R.layout.infowindow_map,
                null);
    }

    @Override
    public View getInfoContents(Marker marker) {



        Item i = items.get(marker.getId());

        TextView tv1 = (TextView) v.findViewById(R.id.textView1);
        ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
        tv1.setText(i.getTitle());


        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .delayBeforeLoading(5000).build();

        imageLoader.getMemoryCache(); 

        imageLoader.displayImage(i.getThumbnailUrl(), iv, options,
                new ImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                            FailReason failReason) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onLoadingComplete(String imageUri,
                            View view, Bitmap loadedImage) {
                        Log.d("MAP", "Image loaded " + imageUri);

                    }

                    @Override
                    public void onLoadingCancelled(String imageUri,
                            View view) {
                        // TODO Auto-generated method stub

                    }
    });

        return v;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub
        return null;
    }

}

我有两个问题:

当我们know InfoWindow 被绘制并随后对其进行更改时(在我的情况下,ImageView 上的新 BitMap)未显示/InfoWindow 未更新。当imageLoader 完成时,我如何“通知”InfoWindow 重新加载自身?当我放

marker.showInfoWindow()

进入onLoadingComplete,它创建了一个无限循环,标记将弹出,开始加载图像,弹出自身等。

我的第二个问题是在慢速网络连接上(模拟代码中的 5000 毫秒延迟),InfoWindow 中的ImageView 将始终显示最后加载的图像,无论该图像是否属于该@ 987654333@/Marker

关于如何正确实施此功能的任何建议?

【问题讨论】:

    标签: android google-maps infowindow universal-image-loader


    【解决方案1】:

    当您收到模型更新时,您应该在当前显示信息窗口的标记上执行Marker.showInfoWindow()

    所以你需要做三件事:

    1. 创建模型而不是把所有的下载放到InfoWindowAdapter
    2. 保存对标记的引用(称为markerShowingInfoWindow
      来自getInfoContents(Marker marker)
    3. 当模型通知您下载完成时调用
    if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
        markerShowingInfoWindow.showInfoWindow();
    }
    

    【讨论】:

    • 如果有人解决了问题,谁能把代码放上来?
    • 编程不是复制粘贴操作。我的回答应该很容易理解,如果不是,您可以提出问题来澄清问题。
    • 如果用户在onLoadingComplete之前点击了另一个标记,错误的infoWindow不会收到那个下载吗?
    • @Ejmedina 信息窗口不接收下载。在我的架构命题模型中存储图像,通知视图控制器(活动/片段),它检查当前显示的信息窗口是否应该更新:当下载的图像与显示信息窗口的模型对象相关联时。
    • @MaciejGórski 嘿,谢谢.. 我认为方法已经改变..markerShowingInfoWindow.isInfoWindowShown().. 对我有用..
    【解决方案2】:

    我做了类似的事情。 这仍然给了我经济衰退的错误

    if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) {
        markerShowingInfoWindow.showInfoWindow();
    }
    

    所以我所做的只是关闭窗口并再次打开它

    if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) {
    
        markerShowingInfoWindow.hideInfoWindow();
        markerShowingInfoWindow.showInfoWindow();
    
    }
    

    对于相同答案的更详细版本,这里是我原来的灵魂LINK

    【讨论】:

    • 这看起来更像是对已接受答案的评论。如果您真的需要这样做,那么它似乎是 Google Maps Android API v2 中的一个错误。我从来没有遇到过这个错误,没有使用隐藏也没有问题......
    • 再次调用 .showInfoWindow 对我有用!感谢您的想法
    【解决方案3】:

    我也遇到了同样的情况,用下面的代码解决了。

    在我的适配器中,我添加了公共变量

    public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
    
        public String ShopName="";   
    
        -------
        -------
    
         @Override
        public View getInfoWindow(Marker arg0) {
    
             View v;
             v = mInflater.inflate(R.layout.info_window, null);
    
             TextView shop= (TextView) v.findViewById(R.id.tv_shop);
    
             shop.setText(ShopName);
    
    
        }
    }
    

    并在我的主要活动中添加了 MarkerClickListener

    ----
    
    MarkerInfoWindowAdapter mMarkerInfoWindowAdapter;
    
    ----
    ----
    
    @Override
    public void onMapReady(GoogleMap googleMap) {
    
    
        mMarkerInfoWindowAdapter = new MarkerInfoWindowAdapter(getApplicationContext());
    
    
    
        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    
            @Override
            public boolean onMarkerClick(final Marker arg0) {
    
                mMarkerInfoWindowAdapter.ShopName= "my dynamic text";
    
                arg0.showInfoWindow();
    
                return true;
            }
        }
    
        mMap.setInfoWindowAdapter(mMarkerInfoWindowAdapter);
    
    
    }
    

    【讨论】:

      【解决方案4】:

      我已经使用了本文中的代码,效果很好。

      http://androidfreakers.blogspot.de/2013/08/display-custom-info-window-with.html

      【讨论】:

      • 不鼓励仅链接答案。
      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2013-03-31
      • 1970-01-01
      • 2015-07-09
      相关资源
      最近更新 更多