【发布时间】:2020-03-29 02:03:21
【问题描述】:
我想显示从火力基地数据库中检索到的每个标记的信息。但我无法使用片段,因为有很多信息,如图像和电子邮件 ID。我尝试使用 Infowindo,但对于所有标记,仅显示最新数据的信息。
mUsers.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot s : dataSnapshot.getChildren()) {
final member user = s.getValue(member.class);
LatLng location = new LatLng(user.lat, user.lon);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v= getLayoutInflater().inflate(R.layout.coustume,null);
TextView nam=v.findViewById(R.id.name);
TextView emai=v.findViewById(R.id.email);
TextView famy=v.findViewById(R.id.family);
TextView seed=v.findViewById(R.id.plant);
ImageView image=v.findViewById(R.id.imagev);
nam.setText(user.name);
Picasso.get().load(user.imagepath).into(image);
emai.setText("Email ID:"+user.email);
famy.setText("Family Members: " + user.numbf);
seed.setText("Plants: " +user.numbs);
LatLng location = new LatLng(user.lat, user.lon);
mMap.addMarker(new MarkerOptions().position(location).title(user.name)).setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
return v;
}
});
mMap.addMarker(new MarkerOptions().position(location).title(user.name)).setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});`
这是我的最终输出,当我点击下一个标记信息时它不会改变
【问题讨论】:
标签: java android google-maps google-maps-markers