-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript1.js
More file actions
90 lines (78 loc) · 2.55 KB
/
Copy pathscript1.js
File metadata and controls
90 lines (78 loc) · 2.55 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var map;
var markers = [];
var polyline;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 0, lng: 0 },
zoom: 2
});
}
function showMaps() {
clearMap();
document.getElementById('map-container').style.display = 'block';
fetchDataAndUpdateMap();
}
function showCoordinates() {
clearMap();
document.getElementById('map-container').style.display = 'none';
fetchCoordinates();
}
function fetchDataAndUpdateMap() {
const apiKey = 'AIzaSyAMDCqRKW6XPHJvxKYqvgr24r4RfhrjAss';
const spreadsheetId = '1HObmilSg2FHjOtueg9tvRn9N7lwkZAt8RYnRw08v-80';
const apiUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/Sheet1?key=${apiKey}`;
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => updateMap(data.values))
.catch(error => {
console.error('Error fetching data:', error);
alert('Error fetching data. Check console for details.');
});
}
function fetchCoordinates() {
const apiKey = 'AIzaSyAMDCqRKW6XPHJvxKYqvgr24r4RfhrjAss';
const spreadsheetId = '1HObmilSg2FHjOtueg9tvRn9N7lwkZAt8RYnRw08v-80';
const apiUrl = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/Sheet1?key=${apiKey}`;
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => displayCoordinates(data.values))
.catch(error => {
console.error('Error fetching data:', error);
alert('Error fetching data. Check console for details.');
});
}
function updateMap(data) {
if (!data || !Array.isArray(data) || data.length === 0) {
console.error('No data received from the API.');
alert('No data received from the API.');
return;
}
// Rest of the code remains unchanged
// ...
}
function displayCoordinates(data) {
if (!data || !Array.isArray(data) || data.length === 0) {
console.error('No data received from the API.');
alert('No data received from the API.');
return;
}
// Rest of the code remains unchanged
// ...
}
function clearMap() {
markers.forEach(marker => marker.setMap(null));
markers = [];
if (polyline) {
polyline.setMap(null);
}
}