如何從firebase實時定位?

[英]How to make realtime location from firebase?


My database

and my code

和我的代碼

var pointRef = myDataRef.child("locations");

function requestMarkerLocations(pointRef) {

snapshot.forEach(function(childSnapshot) {
            var id = childSnapshot.key();

pointRef.child(id).once("value", function (snapshot) {

    var newPosition = id.val();
    var latLng = new google.maps.LatLng(newPosition.lat,
        newPosition.lng);
    var marker = new google.maps.Marker({
        position: latLng,
        map: map
    });        
});
});
}

I need to show all markers and move them after I changed lat and Ing in the firebase.

我需要顯示所有標記並在我在firebase中更改lat和Ing后移動它們。

1 个解决方案

#1


0  

You're using the once() function which reads data only once. You should use the on() instead since it gets called everytime data is updated in the node where the listener has been attached to:

您正在使用只讀取一次數據的once()函數。您應該使用on(),因為每次在附加偵聽器的節​​點中更新數據時都會調用它:

pointRef.child(id).on("value", function (snapshot) {

    var newPosition = id.val();
    var latLng = new google.maps.LatLng(newPosition.lat,
        newPosition.lng);
    var marker = new google.maps.Marker({
        position: latLng,
        map: map
    });        
});

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/01/15/724e765633c247d71036eec8f691063b.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com