从Firebase检索拆分数据

时间:2020-01-25 14:43:23

标签: javascript firebase google-cloud-firestore

Database layout

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.SQLException"%>


<%
    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection cn = DriverManager
            .getConnection("jdbc:jtds:sqlserver://MSI;DatabaseName=LeadManagement;user=sa;password=123456");

    Statement stmt = cn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from userDetail");
%>

我正在根据地图图钉将数据存储在数据库中,现在我正尝试使用存储的数据在同一地点的地图上创建图钉,如何查询coOrds到pinCoOrdsLat / pinCoOrdsLong中这种方式似乎不起作用

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,则应采取以下措施:

db.collection('Pins').get().then(snapshot => {
    snapshot.forEach(pinInfo => {
         pinsToMap(pinInfo)
    });
});

    // trying to set the data

function pinsToMap(pinInfo) {  // IMPORTANT! => pinInfo is a DocumentSnapshot

   const pinName = pinInfo.data().name
   const pinCoOrds = pinInfo.data().coOrds
   const pinToMapInfo = pinInfo.data().Info

   //pinCoOrds is a JavaScript Array with two elements

   const pinCoOrdsLat = pinCoOrds[0];
   const pinCoOrdsLong = pinCoOrds[1];


   //Use pinCoOrdsLat and pinCoOrdsLong the way you want, e.g. calling a leaflet method

}

您会找到here DocumentSnapshot的文档