我正在尝试在地图上放置可绘制的图像作为标记。我正在使用地理查询从特定位置获取数据,它可以正确提取数据,但问题是只有一个标记具有其余的图像标记默认的红色标记。我在if条件下尝试烤面包,以检查它们是否正常工作,但不知何故
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.firstmarker));
在if条件下不能正常工作,它只能设置一张图像,其余图像都没有变化。我做错什么了吗?
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Location");
GeoFire geoFire = new GeoFire(ref);
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latLng1.latitude, latLng1.longitude), 2);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(final String key, GeoLocation location) {
UIDLocation.put(key,location);
marker = mMap.addMarker(new MarkerOptions().position(new LatLng(location.latitude, location.longitude)));
String tagkey = key;
marker.setTag(tagkey);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(key);
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
String cat = dataSnapshot.child("category").getValue().toString();
if (cat.equals("first")){
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.firstmarker));
markers.put(key, marker);
}
else if (cat.equals("second")){
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.secondmarker));
markers.put(key, marker);
}
else if (cat.equals("third")){
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.thirdmarker));
markers.put(key, marker);
}
else{
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.forthmarker));
markers.put(key, marker);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onKeyExited(String key) {
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
}
@Override
public void onGeoQueryReady() {
}
@Override
public void onGeoQueryError(DatabaseError error) {
}
});