简体   繁体   中英

How to add data without quotations from my web to firebase

Using this code i can add database to firebase but with quotations in my longitude and latitude

I want to add database to firebase without quotations in my longitude and latitude so my map will read the longitude latitude without manually removing quotations in firebase

TNX.....

var dbRef= firebase.database().ref('/users /' + userId.value);
var bounds = new google.maps.LatLngBounds();
dbRef.on('value', function(snapshot) {
snapshot.forEach(function(child) {
var data=child.val();
console.log(data);
var marker = new google.maps.Marker({
    position: { lat: data.lat,
        lng: data.lng
    },
    map: map
});
bounds.extend(marker.getPosition());
marker.addListener('click', (function(data) {
    return function(e) {
        infowindow.setContent( data.first_name + "<br>" + data.last_name + "<br>" + data.age + " <br>" + data.symptom + "<br>" + this.getPosition().toUrlValue(6) );
        infowindow.open(map, this);
    }
}(data)));
map.fitBounds(bounds); 
});
});
}
google.maps.event.addDomListener(window, "load", initialize);
const database = firebase.database();
addBtn.addEventListener('click' , (e) => {
    e.preventDefault();
    database.ref('/users /' + userId.value).set({
        first_name: firstName.value,
        last_name: lastName.value,
        age: age.value,
        symptom: symptom.value,
        lat: lat.value,
        lng: lng.value,
    });
});

Try this.

    database.ref('/users /' + userId.value).set({
        first_name: firstName.value,
        last_name: lastName.value,
        age: age.value,
        symptom: symptom.value,
        lat: parseInt(lat.value),
        lng: parseInt(lng.value),
    });

When pushing data, firebase directly saves as "data" for the string. parsing it explicitly might resolve your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM