【发布时间】:2019-05-17 16:33:40
【问题描述】:
我正在尝试获取保存在 firebase 实时数据库中的信息,并使用 Google Maps API 在地图上显示它们。
这是我的火力基地
这是我在地图上的标记
现在它打开并显示用户当前位置,并使用 Geofire 将纬度和经度坐标同步到 Firebase 实时数据库。
现在我可以从 firebase 检索信息并将其显示在地图上,但如果我添加另一个用户,信息仍然相同。为什么?
这是我目前的代码:
// This Function will add/display that marker on the map
function AddDriver(data) {
var LatLng = new
google.maps.LatLng(parseFloat(data.val().lat),parseFloat(data.val().lng
));
var bounds = new google.maps.LatLngBounds();
var marker = new google.maps.Marker({
//title:service,
position:LatLng,
map: map
});
// Attach it to the marker we've just added
google.maps.event.addListener(marker, 'click', function() {
getData();
});
markers[data.key] = marker; // add marker in the markers
array...
document.getElementById("loc").innerHTML = loc_count;
function getData(){
var locationsRef =
firebase.database().ref('Locations/oEyL4QXg1XYAABIBGPvqYbzlNiv2');
console.log(locationsRef);
locationsRef.once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childData);
var contentString = childData;
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(map,marker);
});
});
}
}
【问题讨论】:
标签: javascript android firebase google-maps firebase-realtime-database