forked from simonw/getlatlon.com
/
index.html
311 lines (280 loc) · 12.7 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
<!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;
}
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=ABQIAAAAyYu8a7AdbfUctK3zwwu_2hQcSOGmiixENvtTH313vIgQ4X1LYBSDZW5glZCCklLKePmjvJ8YN_LpPA" type="text/javascript">
</script>
<script>
/* geo-location-javascript v0.4.3
* http://code.google.com/p/geo-location-javascript/ */
var bb_successCallback,bb_errorCallback;
function handleBlackBerryLocation(){if(bb_successCallback&&bb_errorCallback){if(blackberry.location.latitude==0&&blackberry.location.longitude==0)bb_errorCallback({message:"Position unavailable",code:2});else{var f=null;if(blackberry.location.timestamp)f=new Date(blackberry.location.timestamp);bb_successCallback({timestamp:f,coords:{latitude:blackberry.location.latitude,longitude:blackberry.location.longitude}})}parseFloat(navigator.appVersion)>=4.6&&blackberry.location.removeLocationUpdate(handleBlackBerryLocation);bb_errorCallback=
bb_successCallback=null}}
var geo_position_js=function(){var f={},d=null;f.getCurrentPosition=function(i,e,b){d.getCurrentPosition(i,e,b)};f.init=function(){try{if(typeof geo_position_js_simulator!="undefined")d=geo_position_js_simulator;else if(typeof bondi!="undefined"&&typeof bondi.geolocation!="undefined")d=bondi.geolocation;else if(typeof window.google!="undefined"&&typeof window.google.gears!="undefined"){d=google.gears.factory.create("beta.geolocation");f.getCurrentPosition=function(e,b,c){try{d.getCurrentPosition(function(g){typeof g.latitude!="undefined"?
e({timestamp:g.timestamp,coords:{latitude:g.latitude,longitude:g.longitude}}):e(g)},b,c)}catch(a){b({message:a,code:1})}}}else if(typeof navigator.geolocation!="undefined"){d=navigator.geolocation;f.getCurrentPosition=function(e,b,c){d.getCurrentPosition(function(a){typeof a.latitude!="undefined"?e({timestamp:a.timestamp,coords:{latitude:a.latitude,longitude:a.longitude}}):e(a)},b,c)};f.watchPosition=function(e,b,c){try{d.watchPosition(e,b,c);f.clearWatch=function(g){typeof d.clearWatch!="undefined"&&
d.clearWatch(g)}}catch(a){b({message:a,code:1})}}}else if(typeof Mojo!="undefined"&&typeof Mojo.Service!="undefined"&&typeof Mojo.Service.Request!="Mojo.Service.Request"){d=true;f.getCurrentPosition=function(e,b,c){parameters={};if(c){if(c.enableHighAccuracy&&c.enableHighAccuracy==true)parameters.accuracy=1;if(c.maximumAge)parameters.maximumAge=c.maximumAge;if(c.responseTime)if(c.responseTime<5)parameters.responseTime=1;else if(c.responseTime<20)parameters.responseTime=2;else parameters.timeout=3}r=
new Mojo.Service.Request("palm://com.palm.location",{method:"getCurrentPosition",parameters:parameters,onSuccess:function(a){e({timestamp:a.timestamp,coords:{latitude:a.latitude,longitude:a.longitude,heading:a.heading}})},onFailure:function(a){if(a.errorCode==1)b({code:3,message:"Timeout"});else a.errorCode==2?b({code:2,message:"Position Unavailable"}):b({code:0,message:"Unknown Error: webOS-code"+errorCode})}})}}else if(typeof device!="undefined"&&typeof device.getServiceObject!="undefined"){d=device.getServiceObject("Service.Location",
"ILocation");f.getCurrentPosition=function(e,b){var c={};c.LocationInformationClass="BasicLocationInformation";d.ILocation.GetLocation(c,function(a,g,h){g==4?b({message:"Position unavailable",code:2}):e({timestamp:null,coords:{latitude:h.ReturnValue.Latitude,longitude:h.ReturnValue.Longitude,altitude:h.ReturnValue.Altitude,heading:h.ReturnValue.Heading}})})}}else if(typeof window.blackberry!="undefined"&&blackberry.location.GPSSupported){blackberry.location.setAidMode(2);f.getCurrentPosition=function(e,
b){bb_successCallback=e;bb_errorCallback=b;parseFloat(navigator.appVersion)>=4.6?blackberry.location.onLocationUpdate(handleBlackBerryLocation):blackberry.location.onLocationUpdate("handleBlackBerryLocation()");blackberry.location.refreshLocation()};d=blackberry.location}}catch(i){typeof console!="undefined"&&console.log(i)}return d!=null};return f}();
var canGeoDetect = geo_position_js.init();
</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) {
document.getElementById("latlon").innerHTML = lat + ', ' + lon;
document.getElementById("wkt").innerHTML = 'POINT('+lon+' '+lat +')';
}
function getOSMMapType() {
// Usage: map.addMapType(getOSMMapType());
var copyright = new GCopyrightCollection(
'<a href="http://www.openstreetmap.org/">OpenStreetMap</a>'
);
copyright.addCopyright(
new GCopyright(1, new GLatLngBounds(
new GLatLng(-90, -180),
new GLatLng(90, 180)
), 0, ' ')
);
var tileLayer = new GTileLayer(copyright, 1, 18, {
tileUrlTemplate: 'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png',
isPng: false
});
var mapType = new GMapType(
[tileLayer], G_NORMAL_MAP.getProjection(), 'OSM'
);
return mapType;
}
function showMap() {
var geodetectButton = document.getElementById('geodetect');
if (canGeoDetect) {
geodetectButton.style.display='inline';
}
geodetectButton.onclick = function() {
geodetect();
return false;
}
window.gmap = new google.maps.Map2(document.getElementById('gmap'));
gmap.addControl(new google.maps.LargeMapControl());
gmap.addControl(new google.maps.MapTypeControl());
gmap.addMapType(getOSMMapType());
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();
}
);
// Default view of the world
gmap.setCenter(
new google.maps.LatLng(43.834526782236814, -37.265625), 3
);
/* 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 geocodeAccuracyToZoomLevel = [
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 = geocodeAccuracyToZoomLevel[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);
}
function geoDetectSuccess(p) {
gmap.setCenter(new google.maps.LatLng(p.coords.latitude,
p.coords.longitude),
13); //post code (hack since not all detect methods include accuracy)
}
function geodetect() {
geo_position_js.getCurrentPosition(
geoDetectSuccess,
function(){
alert("Could not detect location.")
}
);
}
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>
<p><button id="geodetect" style="display:none">Detect location of your browser</button></p>
</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 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></p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
var _uacct = "UA-1090368-4"; urchinTracker();
</script>
</body>
</html>