-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeolocationSnip.htm
92 lines (67 loc) · 2.21 KB
/
GeolocationSnip.htm
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false
&key=ABQIAAAA3MkIWluwirjPGWsAh4ELkBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQdRoAQBDldyi17oFiloFbB_YTFTg"
type="text/javascript">
</script>
<!-- Please link to my blog http://maxheapsize.com if you use this code. -->
<script type="text/javascript">
var map;
var geocoder;
function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(34, 0), 1);
geocoder = new GClientGeocoder();
}
function addAddressToMap(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
marker = new GMarker(point);
map.setCenter(point, 13);
map.addOverlay(marker);
var addr = document.getElementById('address');
addr.firstChild.data = place.address;
}
}
function showLocation() {
var address = document.forms[0].q.value;
geocoder.getLocations(address, addAddressToMap);
}
function findLocation(address) {
document.forms[0].q.value = address;
showLocation();
}
function find_me()
{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
s = position.coords.latitude+","+position.coords.longitude;
document.forms[0].q.value = s;
showLocation();
});
} else {
alert("I'm sorry, but geolocation services are not supported by your browser.");
}
}
find_me();
</script>
</head>
<body onload="initialize()">
<form action="#" onsubmit="showLocation(); return false;">
<p>
<b>Search for an address:</b>
<input type="text" name="q" value="" class="address_input" size="40" />
<input type="submit" name="find" value="Search" />
<button type="button" onclick="find_me()">Find me!</button>
</p>
</form>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
You location is: <span id="address">Unknown</span>.
</body>
</html>