我在firebase上保存了一个包含坐标(LatLng)的列表。我正在尝试使用此代码检索它们,并使用它们添加折线:
ThePath1 = new ArrayList<Double>();
ThePath2 = new ArrayList<Double>();
ThePath = new ArrayList<LatLng>();
databasePaths = FirebaseDatabase.getInstance().getReference("Paths").child("Ola");
databasePaths.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot items: dataSnapshot.getChildren())
{
double infos = items.child("latitude").getValue(double.class);
double info = items.child("longitude").getValue(double.class);
ThePath1.add(infos);
ThePath2.add(info);
}
for (int i = 0; i < ThePath1.size(); i++){
latt = ThePath1.get(i);
longg = ThePath2.get(i);
latLng1 = new LatLng(latt, longg);
ThePath.add(latLng1);
}
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int i = 0; i < ThePath.size(); i++) {
LatLng point = (LatLng) ThePath.get(i);
options.add(point);
}
line = mMap.addPolyline(options);
问题在于ArrayList“ ThePath”似乎为空,因为地图上没有折线出现。如何从Firebase获取纬度和经度?我在这里发布Paths.class和Ola.class。请帮助我,我被困住了。
在这里我发布Paths.class:
import java.util.List;
public class Paths {
String id;
String name;
String city;
String nomos;
String perifereia;
List<Ola> ola;
public Paths(){
}
public Paths(String id, String name, String city, String nomos, String perifereia, List<Ola> ola) {
this.id = id;
this.name = name;
this.city = city;
this.nomos = nomos;
this.perifereia = perifereia;
this.ola = ola;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getCity() {
return city;
}
public String getNomos() {
return nomos;
}
public String getPerifereia() {
return perifereia;
}
public List<Ola> getOla() {
return ola;
}
}
还有Ola.class:
public class Ola {
public double latitude;
public double longitude;
public Ola() {}
public Ola(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
}