-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParkingMap.html
218 lines (189 loc) · 10.2 KB
/
ParkingMap.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hackathon</title>
<style>
/* container to center map */
#containter{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
#map{
height: 80vh;
width: 80vw;
}
html, body{
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="container">
<div id="map"></div>
</div>
<script>
// 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.
let map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 37.3541, lng: -121.9552 },
zoom: 13,
});
let parkingLatitude =[]; //[37, 47, 57, 67];
let parkingLongitude =[];// [-121, -111, -123, -147];
let businessLatitude =[]; //[37, 47, 57, 67];
let businessLongitude =[];// [-121, -111, -123, -147];
var currentLatitude = 37.74638779388551; //TO DO
var currentLongitude = -122.42209196090698; //TO DO
var radius = 1500;
var url1 = "https://api.iq.inrix.com/lots/v3?point=" + String(radius);
var url2 = "http://localhost:8000/gettoken";
//var url2 = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?latitude=37.783926&longitude=-122.433072&radius=8046&open_now=true" + String(currentLatitude) + "%7C" + String(currentLongitude) + "&radius=" + String(radius);
//var url2 = "https://api.yelp.com/v3/businesses/search?latitude=37.783926&longitude=-122.433072&radius=8046&open_now=true" + String(currentLatitude) + "%7C" + String(currentLongitude) + "&radius=" + String(radius);
//Set up query method
//inrix token
var requestOptions1 = {
method: 'GET',
timeout: 0,
headers: {
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcHBJZCI6InVvazl3bGtpYWEiLCJ0b2tlbiI6eyJpdiI6ImU2OGNlNDhkNjkxMmY0MmNhODE0NDk5Y2EyNWU4ZGMzIiwiY29udGVudCI6ImM1OTljYWI0NDljYmY2MmUyNzc1N2E1Y2RlNGI3MzVlZmQxMTM1YTgyMWQwMGJmM2U0Zjk1NzVjMDk4ZWVkMTE4ZjFiMDYyZGZiNDdkOGE3YTQ3MzljOTI4YjRiMGFmZGNlNDZhNDg5MTkzNmE1MzUxNDBjNzBhYjYzYzY3YmM3ZDAzZmM4MTIxZTAxOTQ3YWFjYzBmYjU0MjhjNThjMDVlOWM1MjdkMGE0YTJiMTYzNmQ3MjI5NDY1NmNkOTYyZDhmOTFhZDczMzUwOGU2NTNmYTNjODAzMjQ2MTM2YTA3ZTI3MTM3NGI3ZGY3MmEzMTA2NTg0NTM4ZTVhZWFhNzExYTE3MDAyNjE4NTYzNzg4YmZlY2QzNGQ2MTRhNTUyMTg4NTIyMTE4ZDM4NWZkMmZjZjdlNjdhNDM1OGFiY2U4YTQ2OGMwODRiNTJmMDUwN2ZiYWU2OGIzY2Q3OGQ2YjU5MWQyOTNhN2EzZWY2NDUwMTQ4Zjk0NThiZDczMzY2ZGI1OThiY2EyZTMyMmZkO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0aSI6ImUxNzFiNTI0LWNiZTQtNGZjMy1iYzk0LTcwMDE3YzE2OGRiYSIsImlhdCI6MTY2ODMyNTg1MCwiZXhwIjoxNjY4MzI5NDUwfQ.fRWyHN_2ukqR568WriFmOid6hS5I_RX3BYiAb9cDihA'"
},
mode: "no-cors"
};
var output = fetch(url1, requestOptions1)
.then(response => response.json())
.then(result => {
console.log("get lat lng running");
console.log(result);
//resultLength = value.result.length;
for (var i = 0; i < result.result.length; i++){
parkingLatitude.push(result.result[i].point.coordinates[0]);
parkingLongitude.push(result.result[i].point.coordinates[1]);
}
console.log(parkingLatitude);
console.log(parkingLongitude);
console.log("after getting values");
console.log(result.result.length);
console.log(parkingLatitude);
console.log(parkingLongitude)
console.log("cur: " + parkingLatitude[0]);
console.log("cur: " + parkingLongitude[0]);
for(let i = 0; i < result.result.length; i++){
console.log("for loop running");
console.log("curret lat: " + parkingLatitude[i]);
console.log("curret lng: " + parkingLongitude[i]);
new google.maps.Marker({
position: {lat: parkingLongitude[i], lng: parkingLatitude[i] },
map,
title: "Hello World!",
});
}
})
.catch(error => console.log('error', error));
var output = fetch(url2, requestOptions2)
.then(response => response.json())
.then(result => {
console.log("get lat lng running business");
console.log(result);
for (var i = 0; i < result.businesses.length; i++){
businessLatitude.push(result.result.latitude);
businessLongitude.push(result.result.longitude);
}
console.log(businessLatitude);
console.log(businessLongitude);
console.log("after getting values business");
console.log(result.businesses.length);
console.log(businessLatitude);
console.log(businessLongitude)
console.log("bcur: " + businessLatitude[0]);
console.log("bcur: " + businessLongitude[0]);
for(let i = 0; i < result.businesses.length; i++){
console.log("bfor loop running");
// console.log("bcurret lat: " + businessLatitude[i]);
// console.log("bcurret lng: " + businessLongitude[i]);
new google.maps.Marker({
position: {lat: businessLongitude[i], lng: businessLatitude[i] },
map,
title: "Hello World!",
});
}
})
.catch(error => console.log('error', error));
//var markers = [];
/*
new google.maps.Marker({
position: {lat: 37.3541, lng: -121.9552},
map,
title: "Hello World!",
});
new google.maps.Marker({
position: {lat: 37.4541, lng: -121.9552},
map,
title: "Hello World!",
});
new google.maps.Marker({
position: {lat: 37.6541, lng: -121.9552},
map,
title: "Hello World!",
});
*/
infoWindow = new google.maps.InfoWindow();
const locationButton = document.createElement("button");
locationButton.textContent = "Find current location";
locationButton.classList.add("custom-map-control-button");
map.controls[google.maps.ControlPosition.TOP_CENTER].push(locationButton);
locationButton.addEventListener("click", () => {
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const pos = {
lat: position.coords.latitude,
lng: position.coords.longitude,
};
infoWindow.setPosition(pos);
infoWindow.setContent("You are here!");
infoWindow.open(map);
map.setCenter(pos);
},
() => {
handleLocationError(true, infoWindow, map.getCenter());
}
);
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
});
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(
browserHasGeolocation
? "Error: The Geolocation service failed."
: "Error: Your browser doesn't support geolocation."
);
infoWindow.open(map);
}
window.initMap = initMap;
</script>
<script src= "https://maps.googleapis.com/maps/api/js?key=AIzaSyBcNKOnmq9pHQl2Eq5dzGAMuZNM4N7JwXg&callback=initMap"></script>
</body>
</html>