如何检查是否谷歌地图信息窗口正在更新之前,仍然显示?窗口、地图、信息

2023-09-05 04:29:22 作者:人傻不能怪社会°

我开始工作所显示的信息窗口内的位置,图像的InfoWindowAdapter。我有很多不同的位置,因此可能的是一个位置图像不提供在电话上,并从网站下载。

I started working on an InfoWindowAdapter that is displaying location images inside the InfoWindow. I have a lot of different locations, therefore it is possible that an location image is not available on the phone and is downloaded from the web.

现在的地图API状态如下:

Now the Maps API states the following:

请注意,返回的视图的快照将采取然后地图,以便后续更改视图将不会在地图上的信息窗口反映上呈现。要更新的信息窗口(如后的图像加载),只需拨打showInfoWindow()和视图将被更新。

Note that a snapshot of the returned view will be taken and then rendered on the map so subsequent changes to the view will not be reflected by the info window on the map. To update the info window (e.g., after an image has loaded), just call showInfoWindow() and the view will be updated.

据我了解这一点,我需要跟踪创建,我想更新,并呼吁showInfoWindow一旦加载图像信息窗口中的标记。我有一个ImageDownloadService,将采取如果图像加载完成被通知的处理程序。

As I understand this I need to keep track of the marker that created the info window that I want to updated and call showInfoWindow once the image is loaded. I have an ImageDownloadService that will take a Handler that is notified if an image is finished loading.

如果图像需要时间长一些加载它可能的是,用户打开另一信息窗口或关闭当前窗口滚动而去。问题是,当时我打电话showInfoWindow上的标记再次更新视图我不能肯定的是,信息窗口仍然显示。

If an image takes a little longer loading it is possible that the user opened another InfoWindow or closed the current Window scrolled away. The problem is that at the time I call showInfoWindow on the marker again to update the view I can not be sure that the InfoWindow is still displayed.

有没有办法更新,只有当它仍然显示的信息窗口?

Is there a way to update the InfoWindow only if it is still displayed?

推荐答案

我刚刚已经有类似的问题与的AsyncTask 取值下载和更新的信息窗口之后今天早上我来到了这个小解决方法,应该有希望服务于您的需求,直到谷歌梳理这一个多敲我的头撞在墙上。

I've just been having a similar problem with AsyncTasks downloading and updating an InfoWindow and after much banging my head against the wall this morning I've come up with this little workaround that should hopefully service your needs until Google sort this one out.

我打电话 marker.showInfoWindow()在我的的AsyncTask ,从而重新叫 InfoWindowAdapter 的方法,这是结束了在一个循环中,从来没有正确地传播了我的变化。

I was calling marker.showInfoWindow() in the OnPostExecute() method of my AsyncTask, which re-called the InfoWindowAdapter methods, which was ending up in a loop and never propagating my changes correctly.

我使用的解决方案是保存当前选择的标记和信息窗口查看我想要的显示。我打发在下面例子中的的TextView 正在更新的 DownloadBubbleInfo 的AsyncTask (类似于你的形象线程我相信)。

The solution I used was to store the currently selected marker and the InfoWindow View I wanted displayed. I've chucked in an example below where the TextView is being updated on the DownloadBubbleInfo AsyncTask (similar to your image thread I believe).

            // Setting a custom info window adapter for the google map
        gMap.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            public View getInfoWindow(Marker arg0) {
                return null;
            }

            // Defines the contents of the InfoWindow
            public View getInfoContents(Marker arg0) {
                if (selectedMarker.isInfoWindowShown()) {
                    return infoWindowView;
                } else {
                    // Getting view from the layout file info_window_layout
                    infoWindowView = getLayoutInflater().inflate(
                            R.layout.bubblewindowlayout, null);
                    // Stash the base view in infoWindowView
                    // Getting reference to the TextView to set latitude
                    TextView tvTit = (TextView) infoWindowView
                            .findViewById(R.id.tv_title);
                    tvTit.setText("Fetching data...");

                    // Async the update so we're not slowed down waiting for
                    // the
                    // bubble to populate
                    new DownloadBubbleInfo(context, infoWindowView, arg0)
                            .execute(arg0.getTitle(), arg0.getSnippet());

                    // Returning the view containing InfoWindow contents
                    return infoWindowView;
                }
            }
        });
        gMap.setOnMarkerClickListener(new OnMarkerClickListener() {

            public boolean onMarkerClick(Marker marker) {
                // When a marker is clicked set it as the selected marker so
                // we can track it for the InfoWindow adapter. This will
                // make sure that the correct marker is still displayed when
                // the callback from DownloadBubbleInfo is made to
                // marker.showInfoWindow() which is needed to update the
                // InfoWindow view.
                selectedMarker = marker;
                infoWindowView = null;
                return false;
            }
        });

和从相关行 DownloadBubbleInfo 的AsyncTask

    @Override
protected String[] doInBackground(String... queryparts) {
    // Do the query and stash the results in queryResults and pass to
    // onPostExecute to attach to the mainview (the current view from the
    // main code) and then call showInfoWindow on the marker to re-launch
    // the InfoWindowAdapter methods again to repopulate the InfoWindow view
    // and attach it.
    return queryResults;
}
protected void onPostExecute(String[] results) {
    ((TextView) mainview.findViewById(R.id.tv_title)).setText(results[0]);
    ((TextView) mainview.findViewById(R.id.tv_info)).setText(results[1]);

    marker.showInfoWindow();
    Log.i("Chris-Debug", "Reshowing InfoWindow");
}

现在,这一切都应该确保正确的标志被填充了来自您的的AsyncTask 哎preSTO返回的极其尴尬的另一个角落的正确信息谷歌地图V2为Android API成功地绕行!

Now, all of this should make sure the correct marker is being populated with the correct information returned from your AsyncTask and hey presto another corner of the extremely awkward GoogleMaps v2 for Android API successfully circumnavigated!

 
精彩推荐
图片推荐