我在 firebase 数据库的地理点数组中存储了几个地理点
CollectionReference propRef = db.collection("Prpoerty");
propRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
GeoPoint geoPoint = document.getGeoPoint("vertex");
double lat = geoPoint.getLatitude();
double lng = geoPoint.getLongitude();
points.add (new LatLng(lat, lng));
}
} else {
Log.w("foobar", "Error getting documents.", task.getException());
}
}
});
System.out.println(points);
我期望像标准的 latlng arrayList 之类的东西。 但反而得到了
Displays Error java.lang.RuntimeException: Field 'vertex' is not a com.google.firebase.firestore.GeoPoint at com.google.firebase.firestore.DocumentSnapshot.castTypedValue(com.google.firebase:firebase-firestore@@20.1.0:562)
最佳答案
Firestore 中的所有数组类型字段都将作为列表类型对象返回。您需要编写代码以期望 List<Object>
,然后将每个项目转换到 GeoPoint
.
关于java - 如何将保存在 firestore 数据库中的地理点数组检索到 latLng 数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57101415/