问题描述
我的代码允许我输入经纬度的位置名称,然后地图用标记显示位置。
我遇到的问题是我想让地图显示所有位置,每个位置都有自己的地图标记。
以下是我用来在地图上显示一个位置的代码
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()){
场地场地= s.getValue(Venue.class);
LatLng位置=新LatLng(venue.venueLat,venue.venueLong);
mMap.addMarker(新MarkerOptions()。position(location))。 title(venue.venueName)).setIcon(BitmapDescriptorFactory.defaultMarker());
}
}
$ b $ @覆盖
public void onCancelled(DatabaseError databaseError){
}
});
}
任何帮助都很有帮助
我没有任何错误,只是显示了我已经添加到firebasedatabase的一个位置。
标记标记;
列表< Venue> venueList;
//在onCreate方法中
venueList = new ArrayList<>();
mVenues.push()。setValue(marker);
// 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()){
场地场地= s.getValue(Venue.class);
venueList.add(场地);
(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));
}
}
}
}
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
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));
}
}
}
}
这篇关于Google地图显示来自Firebase的多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!