-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_map.html
220 lines (199 loc) · 7.2 KB
/
weather_map.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
219
220
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#container{
background-color: #0a68b4;
height: 275px;
width: 100%;
margin: auto;
}
.box{
float: left;
height: 200px;
width: 30%;
margin-left: 2.5%;
margin-top: 5px;
background-color: #0d87e9;
align-content: center;
text-align: center;
}
#map-canvas {
height: 400px;
margin: auto;
width: 100%
}
.boxcontent {
text-align: center;
}
h1 {
text-align: center;
margin: 5px;
}
p {
margin: 5px;
}
#lat {
display: none;
}
#lon {
display: none;
}
#submit1 {
display:none;
}
#input {
display:block;
align-content: center;
width:18%;
margin: auto;
}
</style>
</head>
<body>
<input id='lat' type="text">
<input id='lon' type="text">
<button id="submit1">Submit</button>
<div id="container">
<div id="input">
<input id="address" type="text" placeholder="Address">
<button id="submit2">Submit</button>
</div>
<h1></h1>
<div class="box" id="one"><h2>Today</h2><div class="boxcontent"></div></div>
<div class="box" id="two"><h2>Tomorrow</h2><div class="boxcontent"></div></div>
<div class="box" id="three"><h2>Day After Tomorrow</h2><div class="boxcontent"></div></div>
</div>
<div id="map-canvas"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC4KlXE0TvOaRwqr4gBRsxI86CfNLLd8yo"></script>
<script>
var boxes = $('.boxcontent');
var address = $('#address');
address.val('');
var submit = $('#submit2');
var h1 = $('h1');
$.get("http://api.openweathermap.org/data/2.5/forecast/daily", {
APPID: "bad0e7d24e107c9941b785f18818ae6c",
q: "San Antonio, TX",
cnt: 3,
units: "imperial"
}).done(function(data){
console.log(data);
var days = data.list;
console.log(days);
$(h1).html(data.city.name + ", " + data.city.country);
for(i = 0; i < data.list.length; i++){
var day = days[i];
var daytemps = day.temp;
var dayweather = day.weather[0].main;
var weathericon = day.weather[0].icon;
$(boxes[i]).append("<p>High: " + daytemps.max + "</p>");
$(boxes[i]).append("<p>Low: " + daytemps.min + "</p>");
$(boxes[i]).append("<img src='http://openweathermap.org/img/w/" + weathericon + ".png'>");
$(boxes[i]).append("<p>Weather: " + dayweather + "</p>");
console.log(day);
console.log(daytemps.max);
}
}).fail(function(){
alert("Oops");
});
var mapOptions = {
// Set the zoom level
zoom: 4,
// This sets the center of the map at our location
center: {
lat: 29.426791,
lng: -98.489602
}
};
// Render the map
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
draggable: true,
position: mapOptions.center,
map: map,
title: "Your location"
});
google.maps.event.addListener(marker, 'dragend', function(event) {
document.getElementById("lat").value = event.latLng.lat();
document.getElementById("lon").value = event.latLng.lng();
var latitude = parseFloat($('#lat').val());
var longitude = parseFloat($('#lon').val());
$.get("http://api.openweathermap.org/data/2.5/forecast/daily", {
APPID: "bad0e7d24e107c9941b785f18818ae6c",
lat: latitude,
lon: longitude,
cnt: 3,
units: "imperial"
}).done(function(data){
console.log(data);
var days = data.list;
console.log(days);
$(h1).html(data.city.name + ", " + data.city.country);
$(boxes).html('');
for(i = 0; i < data.list.length; i++){
var day = days[i];
var daytemps = day.temp;
var dayweather = day.weather[0].main;
var weathericon = day.weather[0].icon;
console.log(weathericon);
$(boxes[i]).append("<p>High: " + daytemps.max + "</p>");
$(boxes[i]).append("<p>Low: " + daytemps.min + "</p>");
$(boxes[i]).append("<img src='http://openweathermap.org/img/w/" + weathericon + ".png'>");
$(boxes[i]).append("<p>Weather: " + dayweather + "</p>");
console.log(day);
console.log(daytemps.max);
}
})
});
var geocoder = new google.maps.Geocoder();
submit.click(function(){
geocoder.geocode({'address': address.val()}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
console.log("results: ");
console.log(results);
marker.setMap(null);
marker.position = map.center;
marker.setMap(map);
document.getElementById("lat").value = marker.position.lat();
document.getElementById("lon").value = marker.position.lng();
var latitude = parseFloat($('#lat').val());
var longitude = parseFloat($('#lon').val());
$.get("http://api.openweathermap.org/data/2.5/forecast/daily", {
APPID: "bad0e7d24e107c9941b785f18818ae6c",
lat: latitude,
lon: longitude,
cnt: 3,
units: "imperial"
}).done(function(data){
console.log(data);
var days = data.list;
console.log(days);
$(h1).html(data.city.name + ", " + data.city.country);
$(boxes).html('');
for(i = 0; i < data.list.length; i++){
var day = days[i];
var daytemps = day.temp;
var dayweather = day.weather[0].main;
var weathericon = day.weather[0].icon;
console.log(weathericon);
$(boxes[i]).append("<p>High: " + daytemps.max + "</p>");
$(boxes[i]).append("<p>Low: " + daytemps.min + "</p>");
$(boxes[i]).append("<img src='http://openweathermap.org/img/w/" + weathericon + ".png'>");
$(boxes[i]).append("<p>Weather: " + dayweather + "</p>");
console.log(day);
console.log(daytemps.max);
}
})
} else {
alert('Geocoding was not successful - STATUS: ' + status);
}
});
})
</script>
</body>
</html>