如何将保存在消防商店数据库中的地理点数组检索到 latLng 数组列表中



我在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这样的东西。但反而得到了

显示错误 java.lang.Runtime异常:字段"顶点"不是 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

最新更新