/
Findmefam-frontend-jpiao.html
181 lines (159 loc) · 5.4 KB
/
Findmefam-frontend-jpiao.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
<!DOCTYPE html>
<html>
<head>
<title> Find My Fam!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
#map {
width: cover;
height: cover;
z-index: -1;
height: 100%;
position: absolute;
top: 0;
bottom: -200px;
left: 0;
right: 0;
}
#h {
z-index: 0;
width: 250px;
position: absolute;
text-align: center;
right: 560px;
color: aliceblue;
text-shadow: 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000;
font-family: Impact, Charcoal, sans-serif;
}
#inputs {
width: 200px;
z-index: 0;
position: absolute;
right: 580px;
top: 130px;
}
#find {
width: 200px;
z-index: 0;
position: absolute;
right: 580px;
top: 180px;
text-align: center;
}
#floating-panel1 {
width: 200px;
z-index: 0;
position: absolute;
right: 580px;
top: 400px;
text-align: center;
}
#floating-panel2 {
width: 200px;
z-index: 0;
position: absolute;
right: 580px;
top: 460px;
text-align: center;
}
</style>
</head>
<body onload="initMap()">
<div id="map"></div>
<h1 id = "h">Find My Fam! <br>Send Help!</h1>
<div id="floating-panel1">
<input id="address" type="text" value="">
<input id="encode" type="button" value="Test w/ coord. or locations">
</div>
<div id="floating-panel2">
<input id="latlng" type="text" value="">
<input id="decode" type="button" value="Find Your Fam!">
<br>
</div>
<form id="inputs">
<strong>Phone Number:</strong><br>
<input type="text" name="number">
</form>
<br>
<input type="submit" id ="find" value="Find phone" onclick="retrieveData()">
<script type="text/javascript">
function retrieveData(){
//var xhttp = new XMLHttpRequest();
var number = document.getElementById("inputs").elements.number.value;
$.post("http://still-eyrie-93764.herokuapp.com/request", {sent: number}, function (data) {
// can use 'data' in here...
console.log(data);
return data;
});
/*
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("latlng").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST","http://still-eyrie-93764.herokuapp.com/request", true);
xhttp.setRequestHeader("Content-Type", "text/plain");
xhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
xhttp.send(number);*/
}
</script>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 42.9837, lng: -81.2497}
});
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow;
document.getElementById('encode').addEventListener('click', function() {
geocodeAddress(geocoder, map);
});
document.getElementById('decode').addEventListener('click', function() {
geocodeLatLng(geocoder, map, infowindow);
});
}
function geocodeAddress(geocoder, resultsMap) {
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
resultsMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
function geocodeLatLng(geocoder, map, infowindow) {
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var latlng = {lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1])};
geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(6);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
</body>
</html>