Skip to content

Instantly share code, notes, and snippets.

@EvilGoTa
Last active November 6, 2017 16:08
Show Gist options
  • Save EvilGoTa/cc41eec610cb7cc9b1f08ce99597c635 to your computer and use it in GitHub Desktop.
Save EvilGoTa/cc41eec610cb7cc9b1f08ce99597c635 to your computer and use it in GitHub Desktop.
detect coordinates by address input from user
$('#yandex-location').autocomplete({
delay: 300,
source: function(request, responce) {
$.get('https://geocode-maps.yandex.ru/1.x/', {
geocode: request.term,
sizes: 5,
format: 'json'
}, function(data) {
var result = [];
data.response.GeoObjectCollection.featureMember.forEach(function(el, i) {
var el = el.GeoObject;
console.log(el);
result.push({
name: el.Point.pos,
value: (el.description?el.description + ', ':'') + el.name,
pos: el.Point.pos,
});
});
console.log(result);
responce(result);
})
},
select: function( event, ui ) {
var latlong = ui.item.pos.split(' ');
$('[name="data[location-lat]"]').val(latlong[1]);
$('[name="data[location-long]"]').val(latlong[0]);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment