forked from springmeyer/latlon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
285 lines (261 loc) · 9.53 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Get Lat Lon - find the latitude and longitude of a point on a map</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<!--
Undocumented feature: www.getlatlon.com/?PLACE zooms straight to that place
-->
<style type="text/css">
body {
margin: 0;
margin-bottom: 3em;
padding: 0;
font-family: "Gill sans", sans-serif;
background-color: #fff;
color: #000;
}
div#hd {
text-align: center;
border-bottom: 2px solid black;
}
div#hd h1 {
margin-bottom: 0;
font-size: 1.5em;
}
div#ft {
border-top: 2px solid black;
}
div#ft p {
width: 500px;
margin: 1em auto;
}
p#builtby {
font-size: 0.8em;
text-align: right;
color: #666;
}
p#code {
font-size: 0.8em;
text-align: right;
color: #666;
}
div#bd {
position: relative;
}
div#gmap {
width: 100%;
height: 400px; /* If you change this don't forget to change the crosshair position to match */
}
div#crosshair {
position: absolute;
top: 192px;
height: 19px;
width: 19px;
left: 50%;
margin-left: -8px;
display: block;
background: url(crosshair.gif);
background-position: center center;
background-repeat: no-repeat;
}
</style>
<script src="http://www.google.com/jsapi?key=ABQIAAAAsr9ctZeEunPDrlxJGu21iBTlt8xf3s10eGJdw9dwSKJl_q8e1hSlA1eYXwUjjNs-vI9MwA4wHK1-xw" type="text/javascript">
</script>
<script type="text/javascript">
google.load('maps', '2'); // Load version 2 of the Maps API
function timezoneLoaded(obj) {
var timezone = obj.timezoneId;
if (!timezone) {
return;
}
document.getElementById('timezone').innerHTML = timezone;
document.getElementById('timezonep').style.display = 'block';
// Find out what time it is there
var s = document.createElement('script');
s.src = "http://json-time.appspot.com/time.json?callback=timeLoaded&tz=" + timezone;
s.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(s);
}
function timeLoaded(obj) {
if (obj.datetime) {
document.getElementById('datetime').innerHTML = obj.datetime;
document.getElementById('datetimep').style.display = 'block';
}
}
function updateLatLonFields(lat, lon) {
lat = lat.toFixed(5);
lon = lon.toFixed(5);
document.getElementById("latlon").innerHTML = lat + ', ' + lon;
document.getElementById("wkt").innerHTML = 'POINT('+lon+' '+lat +')';
document.getElementById("geojson").innerHTML = '{ "type": "Point", "coordinates": [' + [lon, lat] + '] }';
document.getElementById("wikipedia").innerHTML = '{{Coord|' + lat + '|' + lon + '|display=title}}';
}
function showMap() {
window.gmap = new google.maps.Map2(document.getElementById('gmap'));
gmap.addControl(new google.maps.LargeMapControl());
gmap.addControl(new google.maps.MapTypeControl());
gmap.enableContinuousZoom();
gmap.enableScrollWheelZoom();
var timer = null;
google.maps.Event.addListener(gmap, "move", function() {
var center = gmap.getCenter();
updateLatLonFields(center.lat(), center.lng());
// Wait a second, then figure out the timezone
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function() {
document.getElementById('timezonep').style.display = 'none';
document.getElementById('datetimep').style.display = 'none';
// Look up the timezone using geonames
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = "http://ws.geonames.org/timezoneJSON?lat=" + center.lat() +
"&lng=" + center.lng() + "&callback=timezoneLoaded";
document.getElementsByTagName("head")[0].appendChild(s);
}, 1500);
});
google.maps.Event.addListener(gmap, "zoomend", function(oldZoom, newZoom) {
document.getElementById("zoom").innerHTML = newZoom;
});
google.maps.Event.addDomListener(document.getElementById('crosshair'),
'dblclick', function() {
gmap.zoomIn();
}
);
/* HAITI */
getOsmUrl = function (a,b,c) {
var url = 'http://tile.openstreetmap.org/' + b + "/" + a.x + "/" + a.y + ".png";
return url;
}
var copycol1 = new GCopyrightCollection("");
var copy1 = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)), 0, "openstreetmap.org");
copycol1.addCopyright(copy1);
var osm = new GTileLayer(copycol1,1,17);
osm.myBaseURL = "http://tile.openstreetmap.org/";
osm.getTileUrl = getOsmUrl;
osm.isPng = function () { return true;}
osm.getOpacity = function() {return 1.0;}
var osm_map = new GMapType([osm], G_SATELLITE_MAP.getProjection(), "OSM", G_SATELLITE_MAP);
gmap.addMapType(osm_map);
gmap.setMapType(osm_map);
getHaitiUrl = function (a,b,c) {
var url = 'http://live.openstreetmap.nl/haiti/' + b + "/" + a.x + "/" + a.y + ".png";
return url;
}
var copycol = new GCopyrightCollection("");
var copy = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)), 0, "haiti.openstreetmap.nl");
copycol.addCopyright(copy);
var haiti = new GTileLayer(copycol,1,17);
haiti.myBaseURL = "http://tile.openstreetmap.org/";
haiti.getTileUrl = getHaitiUrl;
haiti.isPng = function () { return true;}
haiti.getOpacity = function() {return 1.0;}
var haiti_map = new GMapType([haiti], G_SATELLITE_MAP.getProjection(), "OSM Haiti Live", G_SATELLITE_MAP);
gmap.addMapType(haiti_map);
//gmap.setMapType(haiti_map);
// Default view of the world
gmap.setCenter(
new google.maps.LatLng(18.547324589827422, -72.388916015625), 12
);
/* If we have a best-guess for the user's location based on their IP,
show a "zoom to my location" link */
if (google.loader.ClientLocation) {
var link = document.createElement('a');
link.onclick = function() {
gmap.setCenter(
new google.maps.LatLng(
google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude
), 8
);
return false;
}
link.href = '#'
link.appendChild(
document.createTextNode('Zoom to my location (by IP)')
);
var form = document.getElementById('geocodeForm');
var p = form.getElementsByTagName('p')[0];
p.appendChild(link);
}
// Set up Geocoder
window.geocoder = new google.maps.ClientGeocoder();
// If query string was provided, geocode it
var bits = window.location.href.split('?');
if (bits[1]) {
var location = decodeURI(bits[1]);
document.getElementById('geocodeInput').value = location;
geocode(location);
}
// Set up the form
var geocodeForm = document.getElementById('geocodeForm');
geocodeForm.onsubmit = function() {
geocode(document.getElementById('geocodeInput').value);
return false;
}
}
var accuracyToZoomLevel = [
1, // 0 - Unknown location
5, // 1 - Country
6, // 2 - Region (state, province, prefecture, etc.)
8, // 3 - Sub-region (county, municipality, etc.)
11, // 4 - Town (city, village)
13, // 5 - Post code (zip code)
15, // 6 - Street
16, // 7 - Intersection
17, // 8 - Address
17 // 9 - Premise
];
function geocodeComplete(result) {
if (result.Status.code != 200) {
alert('Could not geocode "' + result.name + '"');
return;
}
var placemark = result.Placemark[0]; // Only use first result
var accuracy = placemark.AddressDetails.Accuracy;
var zoomLevel = accuracyToZoomLevel[accuracy] || 1;
var lon = placemark.Point.coordinates[0];
var lat = placemark.Point.coordinates[1];
gmap.setCenter(new google.maps.LatLng(lat, lon), zoomLevel);
}
function geocode(location) {
geocoder.getLocations(location, geocodeComplete);
}
google.setOnLoadCallback(showMap);
</script>
</head>
<body>
<div id="hd">
<h1>Get Lat Lon</h1>
<p>Find the latitude and longitude of a point on a map.</p>
<form action="http://maps.google.com/maps" id="geocodeForm">
<p>
<label for="geocodeInput">Place name: </label>
<input type="text" name="q" id="geocodeInput">
<!-- "Accessible" version of Google Maps: -->
<input type="hidden" name="output" value="html">
<input type="submit" value="Zoom to place">
</p>
</form>
</div>
<div id="bd">
<div id="gmap"></div>
<div id="crosshair"></div>
</div>
<div id="ft">
<p><strong>Latitude, Longitude:</strong> <span id="latlon"></span></p>
<p><strong>WKT:</strong> <span id="wkt"></span></p>
<p><strong>Google Maps zoom level:</strong> <span id="zoom"></span></p>
<p><strong>GeoJSON:</strong> <span id="geojson"></span></p>
<p><strong>Wikipedia:</strong> <span id="wikipedia"></span></p>
<p id="timezonep" style="display: none"><strong>Timezone:</strong> <span id="timezone"></span></p>
<p id="datetimep" style="display: none"><strong>Local time:</strong> <span id="datetime"></span></p>
<p id="builtby">Built by <a href="http://simonwillison.net/2007/Oct/12/latlon/">Simon Willison</a><br>... hacked for haiti by <a href="http://dbsgeo.com">Dane Springmeyer</a></p>
<p id="code">code at <a href="https://github.com/springmeyer/latlon">github</a></p>
</div>
</body>
</html>