-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (109 loc) · 4.68 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
<html>
<head>
<title>Leaflet Address Lookup and Coordinates</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="d-flex mt-5">
<input type="text" class="form-control" name="addr" value="" id="addr" size="58" placehorder="Input your location.."/>
<button type="button" class="btn btn-primary" onclick="addr_search();">Search</button>
</div>
<div id="results" class="mt-3 p-2 border radius"></div>
<br />
<div id="map" style="height: 50%"></div>
<form>
<div class="row mt-2">
<div class="col-md-6">
<label class="form-label">Latitude</label>
<input type="text" class="form-control" name="lat" id="lat" size=12 value="">
</div>
<div class="col-md-6">
<label class="form-label">Longitude</label>
<input type="text" class="form-control" name="lon" id="lon" size=12 value="">
</div>
</div>
</form>
<!-- <iframe class="mt-5" src="https://docs.google.com/viewer?url=https://teknik-informatika-unsiq.rumahdigitalit.com/file/tTRC4hTxHioc6snp1YnkarGDLOjklgfettTu2OwX.pdf&embedded=true" width="600" height="780" frameborder="0"></iframe> -->
</div>
<script type="text/javascript">
// Jawa Tengah
var startlat = -6.9673453;
var startlon = 109.0020266;
var options = {
center: [startlat, startlon],
zoom: 9
}
document.getElementById('lat').value = startlat;
document.getElementById('lon').value = startlon;
var map = L.map('map', options);
var nzoom = 12;
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: 'OSM'
}).addTo(map);
var myMarker = L.marker([startlat, startlon], {
title: "Coordinates",
alt: "Coordinates",
draggable: true
}).addTo(map).on('dragend', function() {
var lat = myMarker.getLatLng().lat.toFixed(8);
var lon = myMarker.getLatLng().lng.toFixed(8);
var czoom = map.getZoom();
if (czoom < 18) {
nzoom = czoom + 2;
}
if (nzoom > 18) {
nzoom = 18;
}
if (czoom != 18) {
map.setView([lat, lon], nzoom);
} else {
map.setView([lat, lon]);
}
document.getElementById('lat').value = lat;
document.getElementById('lon').value = lon;
myMarker.bindPopup("Lat " + lat + "<br />Lon " + lon).openPopup();
});
function chooseAddr(lat1, lng1) {
myMarker.closePopup();
map.setView([lat1, lng1], 18);
myMarker.setLatLng([lat1, lng1]);
lat = lat1.toFixed(8);
lon = lng1.toFixed(8);
document.getElementById('lat').value = lat;
document.getElementById('lon').value = lon;
myMarker.bindPopup("Lat " + lat + "<br />Lon " + lon).openPopup();
}
function myFunction(arr) {
var out = "<br />";
var i;
if (arr.length > 0) {
for (i = 0; i < arr.length; i++) {
out += "<div class='link-primary' title='Show Location and Coordinates' onclick='chooseAddr(" + arr[i].lat +
", " + arr[i].lon + ");return false;'>" + arr[i].display_name + "</div>";
}
document.getElementById('results').innerHTML = out;
} else {
document.getElementById('results').innerHTML = "Sorry, no results...";
}
}
function addr_search() {
var inp = document.getElementById("addr");
var xmlhttp = new XMLHttpRequest();
var url = "https://nominatim.openstreetmap.org/search?format=json&limit=3&q=" + inp.value;
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
myFunction(myArr);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
</script>
</body>
</html>