gpt4 book ai didi

android - 如何在更新之前检查 Google Maps InfoWindow 是否仍然显示?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:22 27 4
gpt4 key购买 nike

我开始研究在 InfoWindow 中显示位置图像的 InfoWindowAdapter。我有很多不同的位置,因此位置图像可能在手机上不可用,而是从网络上下载的。

现在 Maps API 声明如下:

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,它将接收一个处理程序,如果图像加载完成,该处理程序会收到通知。

如果图像加载时间稍长,则可能是用户打开了另一个 InfoWindow 或关闭了滚动离开的当前窗口。问题是,当我再次调用标记上的 showInfoWindow 来更新 View 时,我无法确定 InfoWindow 是否仍然显示。

有没有办法只在 InfoWindow 仍然显示时更新它?

最佳答案

我刚刚在 AsyncTask 下载和更新 InfoWindow 时遇到了类似的问题,今天早上我的头撞到墙上后,我出现了有了这个小变通办法,在 Google 解决这个问题之前,它有望满足您的需求。

我在 AsyncTaskOnPostExecute() 方法中调用了 marker.showInfoWindow(),它重新调用了 InfoWindowAdapter 方法,它以循环结束并且从未正确传播我的更改。

我使用的解决方案是存储当前选择的标记和我想要显示的 InfoWindow View 。我在下面的示例中删除了 TextView 正在 DownloadBubbleInfo AsyncTask 上更新(我相信类似于您的图像线程)。

            // 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 返回的正确信息,嘿,很快就成功绕过了极其笨拙的 GoogleMaps v2 for Android API 的另一个角落!

关于android - 如何在更新之前检查 Google Maps InfoWindow 是否仍然显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13745818/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com