-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixing.js
55 lines (46 loc) · 1.33 KB
/
fixing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var database = firebase.database();
// Initialize and add the map
function initMap() {
// The location of userPosition
getLocation();
}
//Google Maps Initialization
//USER LOCATION
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
lat = position.coords.latitude;
long = position.coords.longitude;
console.log(lat);
console.log(long);
var userPosition = {
lat: lat,
lng: long
};
// Get a key for a new Post.
var newPostKey = firebase.database().ref("/userPosition").push(userPosition).key;
// Write the new user location data.
var updates = {};
updates['/posts/' + newPostKey] = userPosition;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: userPosition
});
database.ref('userPosition').once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var userCoords = childSnapshot.val();
console.log(userCoords);
//Making new Google Map pins for every location
var newPin = new google.maps.Marker({
map: map,
position: userCoords
});
});
});
return firebase.database().ref().update(updates);
}