Answer the question
In order to leave comments, you need to log in
How to remake this google search function so that everything works through google api key?
There is a function that doesn't work. According to the idea, it should collect the latitude and longitude if I understand correctly when, for example , Moscow is entered in the input search field , since then these collected coordinates move the star map (virtual sky js). But I don’t really understand JS and I don’t understand what to specify in the url field in this code, and based on the fact that Google seems to work only with the api key, where and how to add it there (I already received the key)
Here is the code itself
function makeSearchGoogle() {
var searchInput = $('.search-input').val();
if (searchInput) {
var sessionToken = getSessionToken();
var string = searchInput + '&sessiontoken=' + sessionToken;
$.ajax({
url: '/autocomplete' + string,
method: 'get',
dataType: 'json',
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;
}
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question