簡體   English   中英

如何從 firebase(顫振/飛鏢)正確獲取地理位置數據(緯度、經度)?

[英]how to get geolocation data(latitude, longitude) correctly from firebase (flutter/dart)?

在此處輸入圖像描述

這是我的 firebase 在這個請求上我得到了這種數據

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 中接收。

如何獲得緯度和經度而不是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
    });
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM