-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
189 lines (153 loc) · 5.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Wo ist Martin?</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
<!-- The Map
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
h1 { color: #395FB3; }
#map {
height: 100%;
width: 100%;
position:absolute;
top: 0;
left: 0;
z-index: 0; /* Set z-index to 0 as it will be on a layer below the contact form */
}
#header-box {
padding: 50px 50px 20px 50px;
background-color: rgba(255, 255, 255, 0.65);
z-index: 200;
position: relative;
}
#searchTextField{
padding: 10px;
border-radius: 5px;
border-style: solid;
border-color: rgba(128, 128, 128, 0.38);
}
.beforeMap {
position: relative;
z-index: 100;
}
</style>
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div id="header-box">
<h1 class="beforeMap">Wo ist Martin?</h1>
<input class="u-full-width" placeholder="Tell us where you saw Martin" id="searchTextField">
<button class="button-primary" onclick="savePosition(markerLat, markerLng)">SAVE</button>
</div>
</div>
</div>
<div id="map"></div>
<script type="text/javascript">
var map;
var marker;
var markerLat;
var markerLng;
var autocomplete;
function initMap() {
var myLatLng = {lat: 53.5486471, lng: 9.9861163};
map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 15
});
var geocoder = new google.maps.Geocoder;
map.addListener('click', function(e){
placeMarker(e.latLng, map);
geocodeLatLng(geocoder, map);
});
initAutocomplete();
}
function placeMarker(latLng, map) {
var image = {
url: 'images/cursor.png',
size: new google.maps.Size(100, 200),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(50, 100)
};
var shape = {
coords: [1, 1, 1, 20, 18, 20, 18, 1],
type: 'poly'
};
if(marker){
marker.setMap(null);
}
marker = new google.maps.Marker({
position: latLng,
map: map,
icon: image,
shape: shape,
animation: google.maps.Animation.DROP,
draggable: true,
});
markerLat = marker.position.lat();
markerLng = marker.position.lng();
map.panTo(latLng);
}
function savePosition(markerLng, markerLat){
//console.log(markerLat, markerLng);
var xhttp = new XMLHttpRequest();
var xhttp2 = new XMLHttpRequest();
xhttp.open("GET", "http://localhost:8000/latitude/a/" + markerLat, false);
xhttp.send();
xhttp2.open("GET", "http://localhost:8000/longitude/a/" + markerLng, false);
xhttp2.send();
}
function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('searchTextField')),
{types: ['geocode']}
);
autocomplete.addListener('place_changed', function(e){
var place = autocomplete.getPlace();
var latLng = place.geometry.location;
placeMarker(latLng, map);
});
}
function geocodeLatLng(geocoder, map) {
var latlng = {lat: parseFloat(markerLat), lng: parseFloat(markerLng)};
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById("searchTextField").value = results[1].formatted_address;
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD-ptSi5Ryh7O6cIPYj2WtcwWQgakU08hM&signed_in=true&libraries=places&callback=initMap">
</script>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>