简体   繁体   English

Google地图显示Firebase中的多个标记

[英]Google maps show multiple markers from firebase

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 我没有错误,只是显示我已添加到firebasedatabase的一个位置

   Marker marker;
List<Venue> venueList;

//in onCreate method venueList = new ArrayList<>(); //在onCreate方法中会场列表=新的ArrayList <>();

    mVenues.push().setValue(marker);

//onMaps ready method // onMaps ready方法

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));
                                            }
                }
            }

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM