-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocator.js
35 lines (33 loc) · 1.11 KB
/
geolocator.js
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
var positions = [];
function geolocate() {
const data = {
city: document.getElementById("citta").value,
country: 'Italia',
state: document.getElementById("regione").text,
street: document.getElementById("strada").value,
format: 'json',
};
$.ajax({
type: "GET",
url: 'https://nominatim.openstreetmap.org/search',
data: data,
success: function (data) {
console.log(data);
let menu = document.getElementById("scelta");
for (let j = 0; menu.children.length > 0; j++) {
menu.removeChild(menu.children[0]);
}
positions = [];
for (let i = 0; i < data.length; i++) {
let newOption = document.createElement('option');
newOption.setAttribute("value", i.toString());
newOption.innerHTML = data[i]["display_name"];
menu.appendChild(newOption);
positions.push({
lat: data[i]["lat"],
lng: data[i]["lon"],
});
}
},
});
}