【发布时间】:2019-05-16 21:11:12
【问题描述】:
您好,我正在使用 Android Studio,但在转换从 Firestore 获得的数据时遇到了麻烦。我将数据保存在我的 Firestore 类型 GeoPoint 中,我想查询它并转换为对象类型 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());
}
}
});
这是我得到的
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 { latitude=16.503923, longitude=90.196118 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=-69.424524, longitude=-71.356333 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=69.502257, longitude=71.100474 }
我只需要获取纬度、经度值以设置到 LatLng 对象中。
【问题讨论】:
标签: java android firebase google-cloud-firestore geopoints