I stored a couple of geopoints in a geopoint array in firebase database
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);
I expected something like a standard latlng arrayList. But instead got
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)
All array type fields in Firestore will come back as List type objects. You need to write your code to expect a List<Object>
, then cast each item to GeoPoint
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.