/
index.html
317 lines (288 loc) · 10.9 KB
/
index.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<!DOCTYPE html>
<html>
<head>
<title>What's Open</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-itunes-app" content="app-id=737328384">
<meta charset="utf-8">
<style>
* {
box-sizing: border-box;
}
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 100%;
font-family: Helvetica, sans-serif;
}
#buttons {
position: absolute;
right: 0;
top: 50px;
text-align: right;
}
#buttons button, #buttons input {
font-size: 14pt;
}
#search-field {
max-width: 100px;
text-align: right;
text-overflow: ellipsis;
}
#about {
display: none;
padding: 2px;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
max-width: 500px;
font-size: 9pt;
background-color: #edd;
border: 1px solid black;
}
@media only screen and (max-width: 767px) {
#buttons button { font-size: 12pt; }
#search-field { opacity: .8; }
#appstore-link { float: right; }
}
</style>
<link href="lib/libnotify.css" rel="stylesheet">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true"></script>
<script type="text/javascript" src="lib/humane.min.js"></script>
<script>
var properurl = 'http://whatsopen.pw';
var about; // the about div
var circle; // users location
var infowindow; // the info window, it gets reused
var initialzoom = 14; // default zoom
var map; // the map
var markers = []; // all visible markers
var service; // the places service
var searchfield; // search field
// force redirect from github
if (window.location.href.indexOf('github') > -1)
window.location.replace(properurl);
if (typeof console === 'undefined') console = {};
if (typeof console.log === 'undefined') console.log = function() {};
window.addEventListener('load', initialize);
function initialize() {
// buffalo ny!
var initiallocation = new google.maps.LatLng(42.8864, -78.8786);
var mapOptions = {
zoom: initialzoom,
center: initiallocation,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapcanvas = document.getElementById('map-canvas');
map = new google.maps.Map(mapcanvas, mapOptions);
service = new google.maps.places.PlacesService(map);
infowindow = new google.maps.InfoWindow({
pixelOffset: new google.maps.Size(-20, 0)
});
about = document.getElementById('about');
searchfield = document.getElementById('search-field');
google.maps.event.addListener(map, 'click', infowindow.close.bind(infowindow));
searchfield.onkeydown = function(e) {
if (e.keyCode !== 13)
return;
refresh(this.value);
this.blur();
};
findme();
}
function createmarkers(places) {
var bounds = new google.maps.LatLngBounds();
// clear all existing markers
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers.length = 0;
// loop the places and make markers
for (var i = 0, place; place = places[i]; i++) {
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
var marker = new google.maps.Marker({
map: map,
reference: place.reference,
icon: image,
title: place.name,
position: place.geometry.location
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
var marker = this;
service.getDetails({reference : marker.get('reference')}, function(result) {
if (!result) {
humane.log('failed to lookup details');
return;
}
var title = marker.get('title') || '';
var html = '<b>' + title + '</b><br>';
marker.set('url', result.url);
var url = marker.get('url');
html += '<small>';
if (url) html += '<a href="' + url + '" target=_blank>more info »</a><br>';
if (result.formatted_address) html += result.formatted_address + '<br>';
if (result.formatted_phone_number) html += result.formatted_phone_number + '<br>';
var periods = result.opening_hours && result.opening_hours.periods;
if (periods) {
var now = Date.now();
var deltas = [];
// check if 24 hours... there should be a better way
if (periods.length === 1 && periods[0].open && !periods[0].close) {
html += '<br>Open 24 hours<br>';
} else {
for (var i = 0; i < periods.length; i++) {
var period = periods[i];
if (period.close && period.close.nextDate) {
var delta = (period.close.nextDate - now);
deltas.push(delta);
}
}
var delta = Math.min.apply(Math, deltas);
var d = new Date(now + delta);
delta = delta / 60 / 1000;
var hours = Math.floor(delta / 60);
var minutes = Math.round(delta - (hours * 60));
html += '<br>Closes at ' + formatAMPM(d) + '<br>';
if (hours) {
html += hours;
html += hours === 1 ? ' hour, ' : ' hours, ';
}
html += minutes;
html += minutes === 1 ? ' minute' : ' minutes';
html += ' from now<br>';
}
}
html += '</small>';
infowindow.setContent(html);
infowindow.open(map, marker);
});
});
bounds.extend(place.geometry.location);
}
//map.fitBounds(bounds);
}
function refresh(t) {
var request = {
bounds: map.getBounds(),
location: map.getCenter(),
radius: '1000',
openNow: true
};
switch (t) {
case 'all':
break;
case 'food':
request.types = ['food'];
break;
case 'pizza':
request.types = ['food'];
request.keyword = 'pizza';
default:
request.keyword = t;
break;
}
service.nearbySearch(request, function(results, status, pagination) {
if (status === google.maps.places.PlacesServiceStatus.ZERO_RESULTS) {
results = [];
} else if (status !== google.maps.places.PlacesServiceStatus.OK) {
humane.log('error: ' + status);
return;
}
var s = results.length;
if (s === 20) s += ' (max)';
var res = s === 1 ? 'result' : 'results';
humane.log(s + ' ' + res + ' found for ' + (t || 'all'));
if (s) createmarkers(results);
});
}
function toggleabout() {
about.style.display = about.style.display === 'block' ? 'none' : 'block';
}
/* http://stackoverflow.com/questions/8888491/how-do-you-display-javascript-datetime-in-12-hour-am-pm-format */
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
function findme() {
if (navigator.geolocation) {
humane.log('locating you...');
navigator.geolocation.getCurrentPosition(function(position) {
map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
if (circle) circle.setMap(null);
circle = new google.maps.Circle({
center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
radius: position.coords.accuracy,
map: map,
fillColor: '#0000FF',
fillOpacity: 0.2,
strokeColor: '#0000FF',
strokeOpacity: 0.5
});
map.fitBounds(circle.getBounds());
if (map.getZoom() > 17) map.setZoom(17);
refresh('all');
}, function() {
humane.log('error locating you :(');
});
} else {
humane.log('not supported');
}
}
</script>
</head>
<body>
<div id="map-canvas"></div>
<div id="buttons">
<button id="toggle-about" onclick="toggleabout()">About</button><br>
<button onclick="findme()">Find Me</button><br><br><br>
<button onclick="refresh('all');">All</button><br>
<button onclick="refresh('food');">Food</button><br>
<button onclick="refresh('pizza');">Pizza</button><br>
<input type="text" id="search-field" placeholder="search..." /><br>
</div>
<div id="about">
<button onclick="toggleabout()" style="float: right;">X</button>
What's Open is a free service that uses Google Maps to show nearby places that are now open.<br><br>
The idea is that at 4am, you want to go somewhere to get food, but you don't know what is open at that hour.
What's Open will find all places around you that are currently open, and tell you how long you have until they close.<br><br>
You are limited to 20 search results at a time (Google Maps limit), so if you find you are only seeing 20 search results at a time,
try zooming in and searching again by hitting the all, food, or pizza buttons.<br><br>
What's open is also an iOS app, built for both the iPad and iPhone, which you can download on the app store.<br><br>
<div id="appstore-link">
<a href="https://itunes.apple.com/us/app/whats-open/id737328384?mt=8&uo=4" target="itunes_store"style="display:inline-block;overflow:hidden;background:url(https://linkmaker.itunes.apple.com/htmlResources/assets/en_us//images/web/linkmaker/badge_appstore-lrg.png) no-repeat;width:135px;height:40px;@media only screen{background-image:url(https://linkmaker.itunes.apple.com/htmlResources/assets/en_us//images/web/linkmaker/badge_appstore-lrg.svg);}"></a><br><br>
</div>
Created by: <a href="http://www.daveeddy.com" target="new">Dave Eddy</a><br>
Idea/Design by: <a href="http://skyeillustration.com" target="new">Skye Sawyer</a><br>
OpenSourced on: <a href="https://www.github.com/bahamas10/whats-open" target="new">GitHub</a> (MIT License)<br>
Hosted at: <a href="http://whatsopen.pw" target="new">http://whatsopen.pw</a><br><br>
If you find this service useful, please consider donating<br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="dave@daveeddy.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="whatsopen.pw (bahamas10)">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" style="width: 100px;" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</body>
</html>