嗨,我正在使用 Android Studio,但在转换从 Firestore 获得的数据时遇到了麻烦。我将数据保存在 Firestore 类型 GeoPoint 中,我想查询它并转换为 Object 类型LatLng。
这是我的代码:
final FirebaseFirestore db = FirebaseFirestore.getInstance();
final CollectionReference stores = db.collection("stores");
stores.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.i(TAG,document.getData().get("position").toString());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我得到的
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=29.339555, longitude=169.715858 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=68.085393, longitude=-42.081575 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint …Run Code Online (Sandbox Code Playgroud)