let langGeocoder = "fr" // Expediteur var expeLocList = [] var expeLoc; $('#expeGeocoderPhoton').typeahead({ source: function (query, process) { expeLocList = [] var url = "https://photon.komoot.io/api?q="+query+"&lang="+langGeocoder+"&limit=4&osm_tag=place:city&osm_tag=place:town&osm_tag=place:village&osm_tag=place:municipality"; var res = [] return $.getJSON(url,function(data){ for (var i in data.features){ res.push(data.features[i].properties.name+" ("+data.features[i].properties.state+", "+data.features[i].properties.country+")") expeLocList.push({ name: data.features[i].properties.name, center: data.features[i].geometry.coordinates, fullname: data.features[i].properties.name+" ("+data.features[i].properties.state+", "+data.features[i].properties.country+")" }) } return process(res) }) }, matcher: function(item){ //needed when spelling not exact return true }, afterSelect: function (obj) { for (var i in expeLocList){ if (expeLocList[i].fullname == obj){ expeLoc = expeLocList[i] } } } }) //Destinataire var destLocList = [] var destLoc; $('#destGeocoderPhoton').typeahead({ source: function (query, process) { destLocList = [] var url = "https://photon.komoot.io/api?q="+query+"&lang="+langGeocoder+"&limit=4&osm_tag=place:city&osm_tag=place:town&osm_tag=place:village&osm_tag=place:municipality"; var res = [] return $.getJSON(url,function(data){ for (var i in data.features){ res.push(data.features[i].properties.name+" ("+data.features[i].properties.state+", "+data.features[i].properties.country+")") destLocList.push({ name: data.features[i].properties.name, center: data.features[i].geometry.coordinates, fullname: data.features[i].properties.name+" ("+data.features[i].properties.state+", "+data.features[i].properties.country+")" }) } return process(res) }) }, matcher: function(item){ //needed when spelling not exact return true }, afterSelect: function (obj) { for (var i in destLocList){ if (destLocList[i].fullname == obj){ destLoc = destLocList[i] } } } })