【问题标题】:How to pass data from firebase app to google map in flutter如何在颤动中将数据从firebase应用程序传递到谷歌地图
【发布时间】:2021-02-14 14:47:47
【问题描述】:

我想将一些数据从我的应用内的 Firebase 发送或传递到谷歌地图
例如我想发送和显示一些商店的“坐标”或“行程”

下面的 sn-p 代码使用 url_launcher 启动谷歌地图
我不知道怎么做剩下的。有什么想法我可以举一些例子吗?

    void _openMap() async {
      const url = 'https://www.google.com/maps/search/?api=1&query=52.32,4.917';
      if (await canLaunch(url)) {
        void initState(){
          super.initState();
          canLaunch( "https://maps.google.com/maps/search");
        }

        await launch(url);
      } else {
        throw 'Could not launch $url';
      }
    }

以下代码用于在 firebase 中创建记录

    void createRecord(){
  databaseReference.child("1").set({
    'name': 'Macdonald',
    'location': 'New york'
  });
  databaseReference.child("2").set({
    'name': 'burger king',
    'location': 'Mexico'
  });
}

编辑:有多个不同位置的商店(文档 ID) 例如:麦当劳、汉堡王...等

Screenshot example

【问题讨论】:

    标签: firebase flutter google-maps url


    【解决方案1】:

    如果您的数据在 Firebase 集合中,那么您只需从 Firestore 集合中获取坐标并将其传递给上述 URL。现在可以通过以下代码从您的收藏中获取坐标 首先,您将获取所有文档,然后您将获取每个文档的字段

    final QuerySnapshot result =
              await Firestore.instance.collection('YOUR COLLECTION Name').getDocuments();
    final List<DocumentSnapshot> documents = result.documents;
    
    documents.forEach((data) {
     var cordinates = doc.data['coordinates'];
    });
    

    【讨论】:

    • 谢谢,但我相信这仅适用于单个坐标?我有多个坐标不同的商店,因此位置取决于用户选择
    • 您能告诉我您的 Firebase 中的收藏类型,以便我更好地理解吗?
    • Offers > Document ID > field>shop name, location 所以document id的变化需要重新归属到另一个店铺
    • 请让您的回答更具体,因为目前尚不了解您的字段是否是具有位置作为参数的商店列表,或者您在每个文档中有单个商店,并且如果您有单个文档或列表您知道其 ID 的文档?
    • 是的,它在每个文档中都有一个商店,每个文档都有自己的商店和自己的位置,我知道谁的 ID
    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多