【发布时间】:2017-07-25 22:22:46
【问题描述】:
我的地图上有几个标记。对于他们每个人,我都想为他们添加一个自定义的 infoWindow。
我遇到的问题是每个 infoWindow 都是相同的。我已经阅读了几个堆栈线程,但我还没有弄清楚如何修复它。
我将标记添加到地图的片段
for (int i = 0; i<cityObjects.size(); i++){
CityObject cObject = cityObjects.get(i);
Coordinates loc = cObject.getCoordinates();
LatLng pos = new LatLng(loc.getLatitude(), loc.getLongitude());
mMap.addMarker(new MarkerOptions().position(pos).title(cObject.getName()));
loadInfoWindow(cObject.getImgs().get(0), cObject.getName());
builder.include(pos);
}
自定义 infoWindow 的膨胀方法
public void loadInfoWindow(final String url, final CharSequence title) {
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
arg0.getId();
View v = getActivity().getLayoutInflater().inflate(R.layout.layout_info_window, null);
Button info = (Button) v.findViewById(R.id.infoButton);
info.setText(title);
BitmapLayout back = (BitmapLayout) v.findViewById(R.id.bitmapBackground);
Picasso.with(getContext()).load(url).into(back);
return v;
}
@Override
public View getInfoContents(Marker arg0) {
return null;
}
});
}
我读到了一些关于 setInfoWindowAdapter 是 setter 的内容,因此每次 for 循环迭代时都会覆盖 infoWindow。有没有人对如何识别标记有一个很好的解决方案,以便我可以为不同的布局充气?
【问题讨论】:
-
每个标记都有 lat long,因此在标记单击时,您可以通过比较标记 lat long 来生成布局。
-
@chetanprajapat 太好了,它有效!非常感谢
-
永远欢迎...
标签: java android google-maps infowindow