/
index.html
193 lines (160 loc) · 5.29 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
<html>
<!--
____
/ ___|_ __ ___ ___ _ __ _ _
| | | '__/ _ \/ _ \ '_ \| | | |
| |___| | | __/ __/ |_) | |_| |
\____|_| \___|\___| .__/ \__, |
|_| |___/
____ _ _ _
| _ \ ___ | | __ _ _ __ ___ (_) __| |
| |_) / _ \| |/ _` | '__/ _ \| |/ _` |
| __/ (_) | | (_| | | | (_) | | (_| |
|_| \___/|_|\__,_|_| \___/|_|\__,_|
Yes, everything happens in HTML, CSS and JavaScript using Google's Street
View and Geocoding APIs:
* https://developers.google.com/maps/documentation/streetview/
* https://developers.google.com/maps/documentation/geocoding/
-->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maxiumum-scale=1.0, user-scalable=no" />
<title>Creepy Polaroid</title>
<link href='https://fonts.googleapis.com/css?family=Reenie+Beanie' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Reenie Beanie', cursive;
font-size: 30pt;
text-align: center;
background-color: black;
}
#pics {
width: 600px;
margin-left: auto;
margin-right: auto;
}
.pic {
padding: 1em 1em 2.0em 1em;
background-color: white;
margin-top: 20px;
}
.pic span {
font-weight: bold;
}
#google-streetview {
width: 100%;
margin-bottom: 20px;
}
#intro {
display: none;
}
#fakePic {
background-color: pink;
height: 500px;
padding: 40px;
font-size: 35pt;
}
@media (max-width: 400px) {
#pics {
width: 95%;
}
.pic {
padding: .5em .5em .5em .5em;
}
.pic img {
margin-bottom: 10px;
}
.pic span {
font-size: 14pt;
}
}
</style>
</head>
<body>
<a id="github" href="https://github.com/edsu/creepy-polaroid">
<img style="position: absolute; top: 0; right: 0; border: 0; z-index: 3;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub">
</a>
<div id="pics">
<div id="intro" class="pic">
<div id="fakePic">
<strong>Creepy Polaroid</strong> is a pure HTML/JavaScript app that
shows you a picture from Google Street View for where you are.
<br><br>
Your browser may be asking you if you want to share your current
location. You'll need to let it, if you want to be
<strong>CREEPED OUT!!!</strong>
</div>
<span></span>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
var loc;
function getImage() {
navigator.geolocation.getCurrentPosition(setImage);
}
// silly hack to filter out the "image not found" image
// hopefully legitimate images won't be of size 8470
// and the size of the "image not found" image doesn't change.
function imageFound(url, cb) {
$.ajax(url).done(function(data) {
if (data.length != 8470) cb(url);
});
}
function setImage(position) {
$("#intro").hide();
// round lon/lat to the nearest thousandth to make imprecise
// geolocation less noisy
lon = Math.floor(position.coords.longitude * 10000) / 10000;
lat = Math.floor(position.coords.latitude * 10000) / 10000;
var newLoc = lat + ',' + lon;
// if we've moved try to get a new image
if (newLoc != loc) {
loc = newLoc;
console.log("moved to " + loc);
var url = 'https://maps.googleapis.com/maps/api/streetview?size=1000x1000&sensor=true&location=' + loc;
// only display image once the image has been fetched
var i = new Image();
i.src = url;
i.onload = function() {
// make sure an image was found for the location
imageFound(url, function(url) {
// try to reverse geocode the location to get an address
var addr = "https://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=" + loc;
$.getJSON(addr, function(data) {
// text defaults to the geo coordinates but will use address
// if one was found
var text = loc;
if (data.results && data.results.length > 0) {
text = data.results[0].formatted_address;
}
// add the image element to the DOM and fade it in
var pic = $('<div class="pic"><img id="google-streetview" src="' + url + '"><br><span>' + text + '</span></div>');
pic.hide();
$("#pics").prepend(pic);
pic.fadeIn(2000);
});
});
}
} else {
console.log("haven't moved from " + loc);
}
// check later to see if we've moved
setTimeout(getImage, 10000);
}
$(function() {
// display some text about needing to allow the browser to share location
// if we haven't seen any activity
setTimeout(function() {
if (loc == null) {
$("#intro").fadeIn(2000);
}
}, 4000);
if (navigator.geolocation) {
getImage();
} else {
alert("Sorry you'll need a modern browser if you want to be CREEPED OUT!!");
}
});
</script>
</body>
</html>