-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (92 loc) · 2.5 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
<html>
<head>
<title>SF Neighborhoods</title>
<meta name='viewport' content='width=device-width,initial-scale=1.0,maximum-scale=1.0' />
<meta name="apple-mobile-web-app-capable" content="yes" />
<script src='geometry.js'></script>
<script src='nbh.js'></script>
<script src='sfnbh.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<style>
body {
background: black;
color: white;
font-family: Georgia;
}
div {
padding-top: 1em;
}
#nbh {
font-weight: bold;
color: white;
font-size: 60px;
line-height: 1.0;
}
#result, #noresult, #intro, #trying, #escape, #debug {
color: #888;
}
#intro {
cursor: hand;
}
#neighbor, #distance, #accuracy {
color: white;
}
#noresult, #result, #trying, #escape, #debug {
display: none;
}
</style>
</head>
<body>
<div id='intro'>Where are you?</div>
<div id='trying'>Let's find out.</div>
<div id='result'>It looks like you're in<br/><span id='nbh'></span></div>
<div id='noresult'>It looks like you're outside San Francisco.</div>
<div id='escape'>Want to change that? <span id='neighbor'></span> is only <span id='distance'></span> miles away.</div>
<div id='debug'>Accuracy: <span id='accuracy'></span> meters.</div>
<script>
var firstTry = true;
function locationError(error) {
// TODO: something better than...
console.log(error);
}
function locationSuccess(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
var nbh = findNeighborhood(neighborhoods, {"y": position.coords.latitude, "x": position.coords.longitude });
if (!!nbh) {
$('#nbh').text(nbh);
$('#accuracy').text(Math.round(position.coords.accuracy));
$('#trying').hide();
$('#noresult').hide();
$('#result').show();
$('#debug').show();
} else {
$('#trying').hide();
$('#result').hide();
$('#noresult').show();
}
var neighbor = closestNeighborhood(neighborhoods, {"y": position.coords.latitude, "x": position.coords.longitude });
if (neighbor.name) {
$('#neighbor').text(neighbor.name);
$('#distance').text(Math.round(neighbor.distance*10)/10);
$('#escape').show();
}
window.setInterval(findLocation, 30000);
}
function findLocation() {
if (firstTry) {
$('#trying').show();
firstTry = false;
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(locationSuccess, locationError);
} else {
// TODO: what now
}
}
$(document).ready(function() {
$('#intro').click(findLocation)
});
</script>
</body>
</html>