-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
83 lines (83 loc) · 2.43 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Geocode demo</title>
<script src="dist/geocode.global.js"></script>
<style>
#container {
line-height: 1.33;
}
#container * {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
box-sizing: border-box;
font-family: sans-serif;
}
input {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 16px;
width: 100%;
padding: 0.5em 1em;
}
li {
margin: 1em 0;
}
.address {
font-weight: 600;
margin-bottom: 0.25em;
}
.details {
color: gray;
font-size: 12px;
}
.details a {
color: currentColor;
}
.details span {
display: inline-block;
margin-right: 0.5em;
}
.details span:last-of-type {
margin-right: 0;
}
</style>
</head>
<body>
<div id="container">
<div><input type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="Enter address" /></div>
<div id="output"></div>
</div>
<script>
let input = document.querySelector('input');
let output = document.querySelector('#output');
let lastQuery = '';
function doGeocode() {
let query = document.querySelector('input').value;
if (query === lastQuery) return;
lastQuery = query;
__GEOCODE__.default(query, { limit: 10 }).then(result => {
console.log(result);
output.innerHTML = `
<ol>
${result.results.map(r => `
<li>
<div class="address">${r.address}</div>
<div class="details">
<span><a href="https://maps.google.com.au/?q=${r.latitude},${r.longitude}" target="_blank">Map</a></span>
<span>Lat: ${r.latitude}</span> <span>Lon: ${r.longitude}</span>
<span>Score: ${+r.score.toFixed(2)}</span>
</div>
</li>
`).join('\n')}
</ol>
`;
});
}
doGeocode();
input.addEventListener('keyup', doGeocode);
input.addEventListener('change', doGeocode);
</script>
</body>
</html>