-
Notifications
You must be signed in to change notification settings - Fork 0
/
locator.html
235 lines (202 loc) · 6.76 KB
/
locator.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Geo Locator</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
html,
body {
height: 100%;
margin: 0px;
}
h2 {
display: inline-block;
padding-right: 11px;
font-family: monospace;
}
#map-canvas {
height: 100%;
width: 100%;
margin: auto;
padding: 0;
background: antiquewhite;
}
#location {
position: fixed;
width: 317px;
background-color: white;
border-radius: 11px;
z-index: 1;
top: 57px;
right: 10px;
opacity: 0.8;
text-align: center;
transition: height 0.5s;
height: 99px;
overflow: hidden;
}
#location>span {
font-size: 1.3em;
}
#location>span:nth-of-type(1) {
padding-left: 8px;
}
#location>h2:nth-of-type(2) {
margin-top: 2px;
}
#location:hover {
opacity: 1;
height: 276px;
}
.gps h2 {
display: block;
text-decoration: underline;
}
.gps p {
font-size: 1.3em;
}
#Geo-Code {
padding: 10px;
background-color: greenyellow;
display: inline-block;
margin-top: 15px;
}
.wrap {
position: fixed;
text-align: center;
top: -6px;
right: 58px;
}
.h-line {
height: 1px;
width: 0px;
position: absolute;
border-bottom-width: medium;
border-bottom-style: dashed;
display: none;
}
.v-line {
height: 0px;
width: 1px;
position: absolute;
border-left-width: medium;
border-left-style: dashed;
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<!-- This is my key (key=...). Might not work properly, use yours. -->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCud3zIRNArlw2aoxgyDx7l1tMDaDJtBug"></script>
<script type="text/javascript">
var geocoder;
var map;
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(0, 0);
var mapOptions = {
zoom: 3,
center: myLatlng
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
// To add the marker to the map, use the 'map' property
var image = {
url: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAQAAAAn3TzeAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAAAEgAAABIAEbJaz4AAAJ3SURBVDjLldRfaJV1HMfx13Oejbnpkzbpjz+YFcVIcLF6dhE2EjfaRWjQndFFXdStpqS4LrsRYwQOJHA3WRd5VaDiRbjR5jCIPTCwi+hGUfRYYTqPytzZOF7sOXOn8yj0vfv9+L2/X36f7+f7jRVEKggfh8lwI8wG5YIXpSIIsR5P6RHn5/9E1ASs1WdQr1RwXWbWuBn3yIqxlBYD9nhb0pC6YsqoCYuPwHgVlBg24jVtoCZSE6FNt13WyMJCuRFLSRzxmQ5U/OIb8151yhie02aNt3SaqoNxDsWG7dOCX+11xJRn7HDcUT/KvKRLyRuWnA+18vLfUhhy0tP4yV5XwXo9fncbdDnqfdyy289kObbWSTtxwQeuNGqWp93sB9twxm73srxvfbbjrsPNUH6+4rC72K4PSikMSjBtohlaASdMIzFIqoRWvWDcfY+P+8ZBr1bi8JEPDUnUzNvoz/Cg2YMp631iQLdIYpPno/SmzlV+eNd0VoT1O7vKO//G4S+XvCBRc9px5xRUC8z5x6JukevGfNfihFavCCLnHXucJOmcY9q9h8wh1RKqZi3r2fEESToMgllVStmyhhX0GyierhQG9KNinHq7Z0xinWGbm8HcJcPWYdIMxASqbtqpXZcXXXAnCMKG0BfmwoNQ9+QQbjnoD8piygKXtetXssWbbrim6lPf+9tvOgwZ9Q6WjPhWLZMPTlmoyXR6XUmXXbZ51g5bLQi+sM/LWDTmS/PLSkerfpD43B4b8otH0w23jRpRqbdnZSmUhQXTMp02acsTRrl3zjngRL1SQ7UVzf7v5mqAY1/Z72sHLRU5p2C9ZrDkojsuFkM8BL4Gw0oyt63zAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTEwLTIwVDA2OjA1OjExLTA0OjAwB0u5twAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0xMC0yMFQwNjowNToxMS0wNDowMHYWAQsAAAAASUVORK5CYII=',
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(12, 12),
scaledSize: new google.maps.Size(25, 25)
};
marker = new google.maps.Marker({
position: myLatlng,
map: map,
draggable: true,
title: "My Location",
icon: image
});
google.maps.event.addListener(marker, 'drag', dragMarkerFunc);
google.maps.event.addListener(map, 'dragend', dragEndMapFunc);
google.maps.event.addListener(map, 'dragstart', dragStartMapFunc);
init_lineMarker();
}
function init_lineMarker() {
var mapTop = $('#map-canvas').offset().top;
var mapLeft = $('#map-canvas').offset().left;
var mapHeight = $('#map-canvas').height();
var mapWidth = $('#map-canvas').width()
$('#mapVLine').height(mapHeight);
$('#mapHLine').width(mapWidth);
$('#mapVLine').css('top', mapTop);
$('#mapVLine').css('left', mapLeft + (mapWidth / 2));
$('#mapHLine').css('left', mapLeft);
$('#mapHLine').css('top', mapTop + (mapHeight / 2));
}
function codeAddress(event) {
event.preventDefault();
event.stopPropagation();
var address = document.getElementById('address').value;
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
marker.setPosition(results[0].geometry.location);
map.setZoom(14);
updateLocation();
} else {
alert('Address search says : ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
var i = 0;
function dragMarkerFunc() {
updateLocation();
}
function dragEndMapFunc() {
marker.setPosition(this.getCenter());
updateLocation();
$('#mapVLine').hide();
$('#mapHLine').hide();
}
function dragStartMapFunc() {
$('#mapVLine').show();
$('#mapHLine').show();
}
function updateLocation() {
var lat = marker.position.lat(),
long = marker.position.lng();
$('#lati-000').text(Math.round(lat * 1e6)/1e6);
$('#longi-000').text(Math.round(long * 1e6)/1e6);
$(".gps .lat").text(decimalToDMS(lat) + (lat<0 ? ' S' : ' N'));
$(".gps .lon").text(decimalToDMS(long) + (long<0 ? ' W' : ' E'));
}
// converts lat-long to GPS coordinates
function decimalToDMS(D){
return [Math.abs(0|D), '° ', 0|(D<0?D=-D:D)%1*60, "' ", Math.round(D*60%1*60 * 1e3)/1e3, '"'].join('');
}
</script>
</head>
<body>
<div id="location">
<h2>Latitude:</h2><span id="lati-000">0.0</span><br>
<h2>Longitude:</h2><span id="longi-000">0.0</span>
<div class="gps">
<h2>GPS Coordinates</h2>
<p class="lat">0° 0' 0.0"</p>
<p class="lon">0° 0' 0.0"</p>
</div>
</div>
<div id="map-canvas"></div>
<div class="wrap">
<form id="Geo-Code" onsubmit="codeAddress(event)">
<input id="address" type="textbox" placeholder="Enter Street Name, Area">
<input type="submit" value="Geocode">
</form>
</div>
<div id='mapVLine' class="v-line"></div>
<div id='mapHLine' class="h-line"></div>
</body>
</html>