Answer the question
In order to leave comments, you need to log in
The error Uncaught TypeError: Cannot read property 'predictions' of undefined takes off how to fix in my case?
Here is the function itself
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;
}
}
});
}
}
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