如何在flutter中将数据从firebase应用程序传递到谷歌地图 [英] How to pass data from firebase app to google map in flutter

查看:41
本文介绍了如何在flutter中将数据从firebase应用程序传递到谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to send or pass some data from Firebase inside my app into google map
for example I want to send and display some "coordinate" or "itinerary" of a shop

下面的代码片段使用 url_launcher 启动谷歌地图
我不知道剩下的怎么办.有什么想法可以用一些例子吗?

The snippet code below launch google map using url_launcher
I don't know how to do the rest. Any ideas I could use some examples ?

    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 中创建记录

The code below is for creating records inside firebase

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

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

Edit : There is multiple shop with different location (document id) ex : macdonald, burger king...etc

截图示例

推荐答案

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

If your data is in Firebase collection then you have to just fetch the coordinates from your Firestore collection and pass it to the above URL. now fetching the coordinates from your collection can be done by below code first you will fetch all documents and then you will get the field of each document

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'];
});

这篇关于如何在flutter中将数据从firebase应用程序传递到谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆