-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.html
More file actions
64 lines (55 loc) · 1.84 KB
/
demo.html
File metadata and controls
64 lines (55 loc) · 1.84 KB
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
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252"></head><body>
<p>Ziptastic JavaScript Demo</p>
<p>------------------------------------------</p>
Zipcode: <input value="42701" kl_virtual_keyboard_secure_input="on" id="zip" name="zip" type="text"><br><br>
<button onclick="forwardGeo()">Forward Geocoding</button>
<br>
<br>
<button onclick="getLocation()">Reverse Geocoding</button>
<p>------------------------------------------</p>
<ul id="location"></ul>
<p>------------------------------------------</p>
<script src="demo_files/jquery-1.js"></script>
<script language="JavaScript">
var x = document.getElementById("location");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(reverseGeo);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function makeRequest(xurl){
console.log("successfuly got location");
$.ajax({
url: xurl,
type: 'GET',
dataType: 'json',
beforeSend: setHeader
}).done(function(data) {
$.each(data[0], function(index, value){
$(x).append('<li>' + index + ' : ' + value + '</li>')
});
}).error(function(errdata){ console.log(errdata);
});
function setHeader(xhr) {
xhr.setRequestHeader('x-key', '88ad38789b858209141ac5699250d7370d5f1861');
}
}
function reverseGeo(position){
var url = "https://zip.getziptastic.com/v3/reverse/" + position.coords.latitude + "/" + position.coords.longitude + "/" + 5000 + "";
makeRequest(url);
}
function forwardGeo() {
var zipcode = document.getElementById("zip");
var url = "https://zip.getziptastic.com/v3/US/" + zipcode.value;
makeRequest(url);
}
</script>
</body></html>