Меня пытались сохранить координаты из базы данных firebase в переменную, но когда я ее использую, появляется сообщение «Неопределенная переменная». Поэтому я хочу знать, как сохранить его в переменной (я новичок ie в javascript)
Вот код файла HTML `` Пример листовки
<!-- include leaflet css and javascript -->
<link rel="stylesheet" crossorigin=""
href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet-src.js"
crossorigin=""></script>
<script src="leaflet-polycolor.min.js"></script>
<!-- include our own css -->
<link rel="stylesheet" href="leaflet-example.css" />
<!-- we include the javascript at the bottom, see below -->
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-functions.js"></script>
<div id="map"></div>
<!-- include our own javascript -->
<script src="leaflet-example.js"></script>
</body>
And Here is Js file
```
var leafletPolycolor = require('leaflet-polycolor');
leafletPolycolor.default(L);
// Your web app's Firebase configuration
var firebaseConfig = {
// Acctually have a config but I have to keep it
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var database = firebase.database();
var ref = database.ref("/coordinates/");
var sto;
var functions = firebase.functions;
var map = L.map('map', {
center: [45.1834782, 5.7831946],
zoom: 20
});
ref.once('value').then(function(snapshot) {
sto=snapshot.val();
}, function(error) {
console.error(error);
});
console.log(sto);
L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}"", {foo:
"bar"}).addTo(map);
var latLngs = [[45.187273, 5.758124], [45.182772, 5.758516], [45.185767, 5.747106],
[45.176569, 5.752082], [45.171863, 5.757120], [45.168354, 5.755178]];
var colors = ["red", "red", "red", "green", "yellow", "yellow"];
var polyline = L.polycolor(sto,{ colors: colors,weight: 5 }).addTo(map);
А это моя база (https://i.stack.imgur.com/7pSae.png