Вот сама функция
function makeSearchGoogle() {
var searchInput = $('.search-input').val();
if (searchInput) {
var sessionToken = getSessionToken();
var string = searchInput + '&sessiontoken=' + sessionToken;
$.ajax({
url: 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' + string + '&key=AIzaSyCSL1_nsETBMG-E3_7Yk2N7wF5kZikNZZI',
method: 'get',
dataType: 'jsonp',
beforeSend: function () {
$b.addClass('is-searching');
},
complete: function (d) {
$b.removeClass('is-searching');
if (typeof d.responseJSON.predictions != 'undefined' && d.responseJSON.predictions.length) {
var data = d.responseJSON.predictions;
var html = '';
var firstId;
$.each(data, function (k, v) {
if (k < 6) {
var parts = v.description.split(', ');
var name = parts[0];
parts.shift();
var other = parts.join(', ');
var active = k == 0 ? ' active' : '';
firstId = v.place_id;
html = html + '<div class="suggestion' + active + '" data-place="' + v.place_id + '">' + ' <b>' + name + '</b>' + (other ? ', ' : '') + other + '</div>';
}
});
$('.suggestions > div').html(html);
if (html == '') {
$('.suggestions').removeClass('show');
} else {
if (setIfLoads && firstId && typeof getStarmapDetails != 'undefined') {
getStarmapDetails(firstId);
}
if (makePick) {
makePick = false;
$('.suggestions').removeClass('show');
$('.suggestion').eq(0).click();
} else {
$('.suggestions').addClass('show');
}
}
setIfLoads = false;
}
}
});
}
}