Skip to content

Instantly share code, notes, and snippets.

@oiljin
Created April 2, 2015 07:19
Show Gist options
  • Save oiljin/e734eb0b3441abc725de to your computer and use it in GitHub Desktop.
Save oiljin/e734eb0b3441abc725de to your computer and use it in GitHub Desktop.
window.cities = [];
$('#get-geo').on('click', function (e) {
e.preventDefault();
var $list = $('#ccc li');
$list.each(function (index, el) {
var $that = $(el),
name = $that.find('p').html(),
id_city = $that.attr('data-id');
ymaps.geocode(name, { results: 1 }).then(function (res) {
try{
var firstGeoObject = res.geoObjects.get(0),
coord = firstGeoObject.geometry.getCoordinates();
if (coord.length) {
$that.find('.x').html(coord[0]);
$that.find('.y').html(coord[1]);
window.cities.push({id: id_city, latitude: coord[0], longitude: coord[1]});
}
} catch(e){
console.log('Error: ' + name);
}
}, function (err) {
// Если геокодирование не удалось, сообщаем об ошибке.
alert(err.message);
});
});
});
$('#set-geo').on('click', function (e) {
e.preventDefault();
$.ajax({
dataType: "json",
type: "post",
url: "index.php?option=com_gate&controller=location&task=update_geo",
data: {cities: window.cities},
success: function (resp) {
window.location.reload();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment