0

I have code that allows me to input the location name with the lat and longitude and then the map displays the location with a marker.

The issue i am having is that i want the map to show all the locations, each with its own marker on the map.

Below is the code i have used to get the one location showing on the map

public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    googleMap.setOnMarkerClickListener(this);
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mVenues.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot s : dataSnapshot.getChildren()){
                Venue venue = s.getValue(Venue.class);
                LatLng location=new LatLng(venue.venueLat,venue.venueLong);
                mMap.addMarker(new MarkerOptions().position(location).title(venue.venueName)).setIcon(BitmapDescriptorFactory.defaultMarker());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

Any help is much apreciated

I have no errors just shows the one location that i have added to the firebasedatabase

Ele
  • 33,468
  • 7
  • 37
  • 75
Seamy20
  • 35
  • 1
  • 10

1 Answers1

0
   Marker marker;
List<Venue> venueList;

//in onCreate method venueList = new ArrayList<>();

    mVenues.push().setValue(marker);

//onMaps ready method

public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mVenues.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot s : dataSnapshot.getChildren()){
                Venue venue = s.getValue(Venue.class);

                venueList.add(venue);
                for (int i = 0; i < venueList.size(); i++)
                {
                    LatLng latLng = new LatLng(venue.venueLat,venue.venueLong);
                    if (mMap != null) {
                        marker = mMap.addMarker(new MarkerOptions().position(latLng).title(venue.venueName));
                                            }
                }
            }

        }
Seamy20
  • 35
  • 1
  • 10