【发布时间】:2021-02-14 17:51:54
【问题描述】:
我正在开发一个使用 Google Maps Api 的网络应用程序。这是我的问题 我试图将一些 Google 标记保存到 Firebase 数据库中,以便在我的网络中的不同位置检索它们 应用程序,但是当我尝试保存它们时,Gooogle Firebase 会引发错误。
var main_pts = {};
var location1 = {};
location1.latitude = 'Random lat';
location1.longitude = 'Random long';
var location2 = {};
location2.latitude = 'Random lat';
location2.longitude = 'Random long';
main_pts.location1 = location1;
main_pts.location2 = location2;
function create_main_vendor_pts(map){
var main_Google_Markers = [];
var marker1 = new google.maps.Marker({
position: { lat: main_pts.location1.latitude,
lng: main_pts.location1.longitude },
icon: {
labelOrigin: new google.maps.Point(16, 64),
url: "https://drive.google.com/uc?id=0B3RD6FDNxXbdVXRhZHFnV2xaS1E"
},
label: {
text : 'Random',
color : "yellow",
fontWeight : "bold",
fontSize : "20px"
}
});
var marker2 = new google.maps.Marker({
position: { lat: main_pts.location2.latitude,
lng: main_pts.location2.longitude },
icon: {
labelOrigin: new google.maps.Point(16, 64),
url: "https://drive.google.com/uc?id=0B3RD6FDNxXbdVXRhZHFnV2xaS1E"
},
label: {
text : 'Random2',
color : "yellow",
fontWeight : "bold",
fontSize : "20px"
}
});
main_Google_Markers.push(marker1);
main_Google_Markers.push(marker2);
add_Google_Markers_dB(main_Google_Markers);
}
function add_Google_Markers_dB(markers){
var db_object = {};
for(var i = 0; i < markers.length; i ++){
db_object[`marker_${i}`] = markers[i];
}
//console.log(db_object);
var db = firebase.firestore();
var db_reference = db.collection('vendor_points_scheduled').doc('Main_Vendor_pts');
db_reference.set(db_object).then(()=>{
console.log("Data is in... ");
})
}
请注意,我想将 Google 标记保存到 Firebase 以供以后检索,而不是它们的位置.. 等等。我能够通过保存获得我想要的行为
main_Google_Markers 作为全局变量。但是我想要谷歌标记,因为这段代码被多次调用,使得全局变量被初始化
main_Google_Markers = []
【问题讨论】:
-
请不要张贴错误信息的图片。将它们作为文本发布在您的问题中(将它们包含在标题中也很有用)。
标签: javascript firebase google-maps google-cloud-firestore