-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
browser.html
109 lines (101 loc) · 3 KB
/
browser.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OpenCage Data Geocode API Client Example</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.0.0/js/all.js"></script>
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">OpenCage Data Geocode API Client</h1>
<h2 class="title">Query</h2>
<!-- API key -->
<div class="field">
<label class="label">Your API key</label>
<div class="control has-icons-left">
<input class="input" type="text" placeholder="your-api-key" name="key">
<span class="icon is-small is-left">
<i class="fas fa-key"></i>
</span>
</div>
</div>
<!-- Query -->
<div class="field">
<label class="label">Query</label>
<div class="control has-icons-left">
<input class="input" type="text" placeholder="your query (i.e.: `Brandenburg Gate` or `51.508341,-0.125499`)"
name="q">
<span class="icon is-small is-left">
<i class="fas fa-edit"></i>
</span>
</div>
</div>
<!-- Submit / cancel -->
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Submit</button>
</div>
<div class="control">
<button class="button is-text">Cancel</button>
</div>
</div>
<h2 class="title">Result</h2>
<!-- Result -->
<div class="field">
<label class="label">json</label>
<textarea class="textarea" rows="15"></textarea>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="../dist/opencage-api.min.js"></script>
<script>
function clear() {
$('.textarea').val('');
}
function raz() {
$('input[name="key"]').val('');
$('input[name="q"]').val('');
}
function check() {
if ($('input[name="key"]').val() === '') {
return false;
}
if ($('input[name="q"]').val() === '') {
return false;
}
return true;
}
$('.button.is-text').click(function () {
console.log('submit button clicked');
clear();
raz();
});
$('.button.is-link').click(function () {
console.log('submit button clicked');
clear();
if (!check()) {
return;
}
var query = {
pretty: 1,
};
query.key = $('input[name="key"]').val();
console.log('Query with api key', query.key);
query.q = $('input[name="q"]').val();
console.log('Query is', query.q);
opencage
.geocode(query)
.then(data => {
$('.textarea').val(JSON.stringify(data, null, 2));
})
.catch(err => {
$('.textarea').val(err);
});
});
</script>
</body>
</html>