【发布时间】:2017-05-29 00:36:43
【问题描述】:
我能够从 Firebase 数据库中获取所有标记。但我需要使用 Google Maps Clustering 库绘制这些标记。目前,我的地图无法显示 Firebase 数据库中的标记。
这是我添加项目的方法
private void addItems() {
DatabaseReference mapsrefrence=FirebaseDatabase.getInstance().getReference().child("wr");
mapsrefrence.child("pubs").addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
// TODO: handle the post
LocationModel location = postSnapshot.getValue(LocationModel.class);
double latitude = location.getLat();
double longitude = location.getLng();
MyItem offsetItem = new MyItem(latitude, longitude);
mClusterManager.addItem(offsetItem);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "getUser:onCancelled", databaseError.toException());
}
});
}
这是我的集群方法
private void setUpClusterer() {
// Position the map.
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(50.28626380000001, 19.104079100000035), 10));
// Initialize the manager with the context and the map.
// (Activity extends context, so we can pass 'this' in the constructor.)
mClusterManager = new ClusterManager<MyItem>(this, mMap);
// Point the map's listeners at the listeners implemented by the cluster
// manager.
mMap.setOnCameraIdleListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
// Add cluster items (markers) to the cluster manager.
addItems();
}
这就是我称之为集群器的地方
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpClusterer();
//displayClubLocations();
}
【问题讨论】:
标签: android firebase-realtime-database google-maps-android-api-2