如何从 firebase (flutter/dart) 正确获取地理位置数据(纬度、经度)?
how to get geolocation data(latitude, longitude) correctly from firebase (flutter/dart)?
这是我的火力基地
根据这个请求,我得到了这种数据
final firestoreInstance = Firestore.instance;
firestoreInstance.collection("locations").getDocuments().then((querySnapshot) {
querySnapshot.documents.forEach((result) {
print(result.data);
});
});
来自服务器的响应
{12/5/2020: {geohash: u8vybwryv, geopoint: Instance of 'GeoPoint'}} .... and all list of documents
在我使用这个之后
firestoreInstance.collection("test").getDocuments().then((querySnapshot) {
querySnapshot.documents.forEach((result) {
print(result.data['geopoint'].latitude.toString());
});
});
并在调试中接收 null。
如何获取经纬度不为空?
可能对某人有帮助
List<LatLng> polyLinesLatLongs = List<LatLng>(); // our list of geopoints
_someFunction() {
firestoreInstance
.collection("userId") // your collection
.document('history') //your document
.collection("locations") //your collection
.getDocuments()
.then((querySnapshot) {
var fireBase = querySnapshot.documents;
for (var i = 1; i < fireBase.length; i++) {
GeoPoint point = fireBase[i].data['position']['geopoint']; //that way to take instance of geopoint
polyLinesLatLongs.add(LatLng(double.parse('${point.latitude}'),
double.parse('${point.longitude}'))); // now we can add our point to list
});
}
这是我的火力基地 根据这个请求,我得到了这种数据
final firestoreInstance = Firestore.instance;
firestoreInstance.collection("locations").getDocuments().then((querySnapshot) {
querySnapshot.documents.forEach((result) {
print(result.data);
});
});
来自服务器的响应
{12/5/2020: {geohash: u8vybwryv, geopoint: Instance of 'GeoPoint'}} .... and all list of documents
在我使用这个之后
firestoreInstance.collection("test").getDocuments().then((querySnapshot) {
querySnapshot.documents.forEach((result) {
print(result.data['geopoint'].latitude.toString());
});
});
并在调试中接收 null。
如何获取经纬度不为空?
可能对某人有帮助
List<LatLng> polyLinesLatLongs = List<LatLng>(); // our list of geopoints
_someFunction() {
firestoreInstance
.collection("userId") // your collection
.document('history') //your document
.collection("locations") //your collection
.getDocuments()
.then((querySnapshot) {
var fireBase = querySnapshot.documents;
for (var i = 1; i < fireBase.length; i++) {
GeoPoint point = fireBase[i].data['position']['geopoint']; //that way to take instance of geopoint
polyLinesLatLongs.add(LatLng(double.parse('${point.latitude}'),
double.parse('${point.longitude}'))); // now we can add our point to list
});
}