0
Map<String, List<Driver>> markerMap = new HashMap<String, List<Driver>>();
private List<Driver> markerArray = new ArrayList<Driver>();
public void markerDriver() {
markerArray = new ArrayList<>();
Firebase ref = new Firebase(Config.FIREBASE_URL_DRIVER);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getChildrenCount() == 0) {
markerInfo();
} else {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Toast.makeText(MainMapActivity.this, "for", Toast.LENGTH_SHORT).show();
name = snapshot.child("driversName").getValue().toString().trim();
busNum = snapshot.child("busNum").getValue().toString().trim();
latitude = Double.valueOf(snapshot.child("latitude").getValue().toString().trim());
longitude = Double.valueOf(snapshot.child("longitude").getValue().toString().trim());
availableSeat = snapshot.child("availableSeat").getValue().toString().trim();
estimatedTime = snapshot.child("estimatedTime").getValue().toString().trim();
if ((!latitude.equals(null) || latitude.equals(0)) && (!longitude.equals(null) || longitude.equals(0)) && availableSeat.equals("") && (!estimatedTime.equals("") || estimatedTime.equals("0"))) {
convertLatLong();
getTotalPass();
markerArray.add(new Driver(name, totalPassenger, busNum, latitude, longitude, currentLocation, estimatedTime));
markerMap.put("key"+key++, markerArray);
}
}
for (i = 0; i < markerArray.size(); i++) {
createMarker(markerArray.get(i).getDriversName(), markerArray.get(i).getTotalPassenger(), markerArray.get(i).getBusNum(), markerArray.get(i).getLatitude(), markerArray.get(i).getLongitude(), markerArray .get(i).getLocation(), markerArray.get(i).getEstimatedTime());
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(MainMapActivity.this, "markerDriver: " + firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
我把我的ArrayList HashMap的內部,因爲ArrayList的本身並沒有編輯/更新一些數據列表內的能力。所以,我試圖做的是我怎麼獲取的HashMap中的數據和createMarker
如何存儲和檢索HashMap中使用POJO(安卓)多個值
protected void createMarker(String driversName, final int totalPass, final String busNum, double latitude, double longitude, String location, String estimatedTime) {
Marker marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(location)
.snippet("Driver's Name: " + driversName + "\nTotal Passenger: " + totalPass + "\nBus number: " + busNum+"\nEstimated time: "+estimatedTime));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker) {
dialogInfo(marker);
return true;
}
});
}