-
Notifications
You must be signed in to change notification settings - Fork 0
/
display-google-map.js
61 lines (47 loc) · 1.6 KB
/
display-google-map.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
56
57
58
59
60
61
//load the google map
function initMap() {
setTimeout(() => {
//location data from tags (from firebase)
const latitude = parseFloat(document.getElementById("latitude").innerText); //from firebase
const longitude = parseFloat(document.getElementById("longitude").innerText); //from firebase
console.log(latitude);
console.log(longitude);
//position of item (from firebase)
const pos = {
lat: latitude,
lng: longitude
};
//this is the new map
const map = new google.maps.Map(document.getElementById('map'), {
center: pos,
zoom: 9,
disableDefaultUI: true,
});
//marker for location of item
const marker = new google.maps.Marker({
position: pos,
map: map,
});
//create info window
const infowindow = new google.maps.InfoWindow({
content: "Latitude: " + pos["lat"] + "\n" + " Longitude: " + pos["lng"],
});
//when you click on marker show info window
marker.addListener("click", () => {
infowindow.open({
anchor: marker,
map,
shouldFocus: false,
});
});
/*
//when you howver out of marker close window
marker.addListener('onclick', ()=>{
infowindow.close();
});
*/
}, 3000);
//location data from tags (from firebase)
// const latitude = document.getElementById("latitude").innerText; //from firebase
// const longitude = document.getElementById("longitude").innerText; //from firebase
}