var a = prompt("What is your phone number");
var database = firebase.database();
var fruits = database.ref('fruits');
var data = {
name: (a),
//count: (a)
}
database.ref('fruits').push(data);
//fruits.push(data, finished);
function finished(error) {
if (error) {
console.log('ooops');
} else {
console.log('data saved!');
}
}
var ref = firebase.database().ref();
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (error) {
console.log("Error: " + error.code);
});
var playersRef = firebase.database().ref("fruits");
playersRef.orderByChild("name").on("child_added", function(data) {
var PD = (data.val().name);
//pushRef.child("name").onDisconnect().remove();
//var markerLabel = (PD);
confirm(PD)
});
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
var map, infoWindow;
var lat, lng;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 18
//mapTypeId: google.maps.MapTypeId.ROADMAP
});
infoWindow = new google.maps.InfoWindow;
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
var pos = {lat: lat, lng: lng };
_setGeoFire();
var locationsRef = firebase.database().ref("locations");
locationsRef.on('child_added', function(snapshot) {
var data = snapshot.val();
// var phoneNumber = localStorage['phoneNumber']
// var markerLabel = (phoneNumber);
// var markerLabel = document.cookie;
//confirm(document.getElementById("phone").innerHTML)
var ML = localStorage.getItem('phoneNumber');
//var playersRef = firebase.database().ref("players/");
// John: {
// number: 1,
//age: 30
//},
//Amanda: {
// number: 2,
// age: 20
// }
//});
//var ref = firebase.database().ref();
//ref.on("value", function(snapshot) {
// console.log(snapshot.val());
//}, function (error) {
// console.log("Error: " + error.code);
//
//var ratingRef = firebase.database().ref("ratings/");
//ratingRef.orderByValue().on("value", function(data) {
//data.forEach(function(data) {
// console.log("The " + data.key + " rating is " + data.val());
// });
//});
// var ML = localStorage.getItem("phone");
//confirm(ML);
//var markerLabel = (PD)
var markerLabel = "*_*"
var marker = new google.maps.Marker({
position: {
lat: data.User.l[0],
lng: data.User.l[1]
},
map: map,
label: markerLabel,
url: "sms://" + (PD)
// new google.maps.Size(42, 68)
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href = this.url;
What this code does is it asks for the user's phone number, then it writes the phone number into the firebase real-time database, then it reads it and puts the value in a variable. I'm able to confirm the variable with this var PD = (data.val().name);
then confirm(PD)
and I'm able to get the proper value. For some reason whenever I try to set that as a marker label under URL tag for the google maps marker so the user can actually click on the marker, it says PD undefined even though it worked before. Can anyone help me with this?
Comments
Post a Comment