Answer the question
In order to leave comments, you need to log in
Explain how to make it work for you SearchGoogle SearchPhoton on a downloaded site?
There is such a piece of code from a foreign site that I downloaded into html. Everything as a whole works, all the scripts corrected the paths and so on, but the geolocation does not work.
This piece is responsible, as I understand it, for geolocation, which loads data from somewhere when you enter the name of the city in
<input type="text" class="search-input" required="required" value="" placeholder="Search for city or country" />
function makeSearchPhoton() {
var searchVal = $('.search-input').val();
if (searchVal) {
$.ajax({
url: url + '/endpoint/autocomplete/' + searchVal,
method: 'get',
dataType: 'json',
beforeSend: function() {
$b.addClass('is-searching');
},
complete: function(response) {
$b.removeClass('is-searching');
if (response.responseJSON.features.length > 0) {
var htmlOutput = '';
var locations = response.responseJSON.features;
for (var i = 0; i < locations.length; i++) {
var active = i == 0 ? ' active' : '';
var haveState = typeof locations[i].properties['state'] == 'undefined' ? '' : ', ' + locations[i].properties['state'];
htmlOutput = htmlOutput + '<div data-sugg-country="' + locations[i].properties['name'] + '" data-sugg-title="' + locations[i].properties['name'] + '" data-sugg-subtitle="' + locations[i].properties['country'] + '" data-sugg-lat="' + locations[i].geometry.coordinates[1] + '" data-sugg-long="' + locations[i].geometry.coordinates[0] + '" class="suggestion ' + active + '"><b>' + locations[i].properties['name'] + '</b>, ' + locations[i].properties['country'] + haveState + '</div>';
}
$('.suggestions > div').html(htmlOutput);
if (htmlOutput == '') {
$('.suggestions').removeClass('show');
} else {
if (makePick) {
makePick = false;
$('.suggestions').removeClass('show');
$('.suggestion').eq(0).click();
} else {
$('.suggestions').addClass('show');
}
}
}
}
});
}
}
function makeSearchGoogle() {
var searchInput = $('.search-input').val();
if (searchInput) {
var sessionToken = getSessionToken();
var string = searchInput + '&sessiontoken=' + sessionToken;
$.ajax({
url: 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;
}
}
});
}
}
url: url + '/endpoint/autocomplete/
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