我正在将onPostExcecute中的数据检索到infoWindow中。我设法将标题和文本放入infoWindow但无法将图像加载到同一个infoWindow中。我是否正确引用了图像?任何帮助表示赞赏。我评论了我的代码中的内容,其中有些东西可以工作并且无法工作(2项)
@Override
protected void onPostExecute(final ArrayList<Item> arrayList) {
if(isCancelled()) return;
if(googleMap!=null) {
googleMap.clear();
mMarker2Item.clear();
LatLngBounds.Builder boundBuilder = new LatLngBounds.Builder();
for (Item item : arrayList) {
MarkerOptions opts = new MarkerOptions()
.position(item.location())
.title(item.name); // LOAD PERFECT INTO INFOWINDOW
if(item.iconBitmap!=null){
opts = opts.icon(BitmapDescriptorFactory.fromBitmap(item.iconBitmap)); // DOES NOT LOAD INSIDE INFO WINDOW
}
Marker newMarker = googleMap.addMarker(opts);
newMarker.setSnippet(item.vicinity);
//newMarker.setIcon(BitmapDescriptorFactory.fromBitmap(item.iconBitmap));
mMarker2Item.put(newMarker, item);
boundBuilder.include(item.location());
}
try {
if (firstTime) {
firstTime = false;
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(boundBuilder.build(), 200);
googleMap.moveCamera(cameraUpdate);
googleMap.animateCamera(cameraUpdate, 1000, null);
}
} catch (Exception ex) {
}
} else mHandler.postDelayed(new Runnable() {
@Override
public void run() {
onPostExecute(arrayList);
}
}, 500);
}
}
@Override
public void onMapReady(final GoogleMap googleMap) {
googleMap.setMyLocationEnabled(true);
this.googleMap = googleMap;
googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getActivity().getLayoutInflater().inflate(R.layout.maps_infowindow, null);
v.setLayoutParams(new LinearLayout.LayoutParams((int) (mapFragment.getView().getMeasuredWidth() * .9), LinearLayout.LayoutParams.WRAP_CONTENT));
((TextView) v.findViewById(R.id.title)).setText(marker.getTitle()); // WORKS GREAT - COMES FROM onPostExcecute marker
((TextView) v.findViewById(R.id.desc)).setText(marker.getSnippet()); // WORKS GREAT - COMES FROM onPostExcecute marker
((ImageView) v.findViewById(R.id.imageView5)).setImageBitmap(WHAT REFERENCE GOES HERE?????); // DOES NOT WORK :(
return v;
}
});