【发布时间】:2017-10-28 09:41:19
【问题描述】:
我想在 fcmUsers 列表中的标记上显示这些值
当用户点击标记时,它将在 fcmUsers 列表的文本视图中显示自己的值或数据
fcmUsers 列表有 public Long createdat;和 public Long hajjappnum;
DatabaseReference UserRef = FirebaseDatabase.getInstance().getReference().child("GPSLocationHistory").child("DevicesLatest");
UserRef.keepSynced(true);
new GetDataFromFirebase().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
FirebaseDatabase database = FirebaseDatabase.getInstance();
// myRef = database.getReference("GPSLocationHistory/DevicesLatest");
UserRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
latLngList.clear();
mMap.clear();
if (marker != null) {
marker.remove();
}
Toast.makeText(MapsActivity.this, "change", Toast.LENGTH_SHORT).show();
Iterator<DataSnapshot> dataSnapshots = dataSnapshot.getChildren().iterator();
fcmUsers = new ArrayList<>();
i = 0;
while (dataSnapshots.hasNext()) {
DataSnapshot dataSnapshotChild = dataSnapshots.next();
ModelClassFireBase fcmUser = dataSnapshotChild.getValue(ModelClassFireBase.class);
fcmUsers.add(fcmUser);
LatLng latLng = new LatLng(Double.parseDouble(fcmUsers.get(i).lati.toString()), Double.parseDouble(fcmUsers.get(i).longi.toString())); // Use your server's methods
latLngList.add(latLng);
mark1 = mMap.addMarker(new MarkerOptions().title(fcmUsers.get(i).Battery.toString()).position(latLngList.get(i)));//.icon(BitmapDescriptorFactory.fromResource(R.drawable.female4)));
// Toast.makeText(getApplicationContext(), uniqueids.get(i).toString(), Toast.LENGTH_LONG).show();
markerList.add(mark1);
i++;
if (fcmUsers.size() > 0) {
} else {
// Display dialog for there is no user available.
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// for handling database error
}
});
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_widow_layout, null);
// Getting the position from the marker
LatLng latLng = arg0.getPosition();
// Getting reference to the TextView to set latitude
TextView userbattery = (TextView) v.findViewById(R.id.tv_lat);
// Getting reference to the TextView to set longitude
// TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
// ImageView userimage = (ImageView) v.findViewById(R.id.userimage);
userbattery.setText("user battery:" + fcmUsers.get(i-1).Battery.toString());
return v;
}
});
【问题讨论】:
-
我想用标记位置显示 fcmUsers 类的电池
标签: android firebase-realtime-database google-maps-markers android-maps-v2