Last active
November 6, 2017 16:08
-
-
Save EvilGoTa/cc41eec610cb7cc9b1f08ce99597c635 to your computer and use it in GitHub Desktop.
detect coordinates by address input from user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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