Rev 15794 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
15794 | guerimand | 1 | !! this file manage autocompletion for location in France |
2 | !! using official api https://api-adresse.data.gouv.fr |
||
3 | |||
4 | <script> |
||
5 | $$("#location").autocomplete({ |
||
6 | source: function (request, response) { |
||
7 | $$.ajax({ |
||
8 | url: "https://api-adresse.data.gouv.fr/search/?city="+$$("input[name='location']").val()+"&type=municipality&limit=15", |
||
9 | data: { q: request.term }, |
||
10 | dataType: "json", |
||
11 | success: function (data) { |
||
12 | var cities = []; |
||
13 | response($$.map(data.features, function (item) { |
||
14 | if ($$.inArray(item.properties.cities) == -1) { |
||
15 | cities.push(item.properties.cities); |
||
16 | return { label: item.properties.postcode + " - " + item.properties.city, |
||
17 | geoloc: item.geometry.coordinates, |
||
18 | value: item.properties.postcode + " - " + item.properties.city |
||
19 | }; |
||
20 | } |
||
21 | })); |
||
22 | } |
||
23 | }); |
||
24 | }, |
||
25 | select: function(event, ui) { |
||
15801 | guerimand | 26 | $$('#geoloc').val(ui.item.geoloc[1]+","+ui.item.geoloc[0]); |
15794 | guerimand | 27 | } |
28 | }); |
||
29 | </script> |
||
30 |