简体   繁体   English

从Firestore中的集合中获取数据

[英]Get data from collection in firestore

I stored geopoints to an array and now I want to output these on google maps but it wont't work. 我将地理位置保存到数组中,现在我想在Google地图上输出这些地理位置,但无法正常工作。 No markers are set for the new geopoints. 没有为新的地理位置设置标记。

Need help, how can I set the markers on map for the geopoints? 需要帮助,如何在地图上为地理位置设置标记?

firestore database: Firestore数据库:

在此处输入图片说明

code: 码:

   mounted () {

    var map = new google.maps.Map(document.getElementById('mapName'), {
      center: {lat: 0, lng: 0},
      zoom: 20
    });


   fb.usersCollection.where("acctPosition", "==", true).get().then(docs => {
    docs.forEach((coord) => {
     const position = new google.maps.LatLng(coord.latitude,coord.longitude);
     const marker = new google.maps.Marker({
        position,
        map: map
       });
     })
    })
  }

This is the output of console.log(coord.data()) 这是console.log(coord.data())的输出

With this geopoints I would like to set a marker in google maps. 有了这个地理位置,我想在Google地图中设置一个标记。 How to do this? 这个怎么做?

在此处输入图片说明

The following should do the trick: 以下应该可以解决问题:

   fb.usersCollection.get().then(docs => {
    docs.forEach((coord) => {
     const lat = coord.data().acctPosition[0].lat;
     const lng = coord.data().acctPosition[0].lng;
     const position = new google.maps.LatLng(lat, lng);
     const marker = new google.maps.Marker({
        position,
        map: map
       });
     })
    })

docs.forEach() returns a QueryDocumentSnapshot (which "offers the same API surface as a DocumentSnapshot"). docs.forEach()返回QueryDocumentSnapshot (它“提供与DocumentSnapshot相同的API表面”)。 You therefore have to call the data() method to get the doc fields. 因此,您必须调用data() 方法来获取doc字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM