V
V
VPVPVP2020-05-06 14:44:13
JavaScript
VPVPVP, 2020-05-06 14:44:13

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" />

Here is the JS itself ->

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;
                }
            }
        });
    }
}


All this refers to the site where it is all taken from here and then loads it with a drop-down list of cities, etc., etc.. url: url + '/endpoint/autocomplete/
How to make it work for yourself? I tried a stupid way to create an empty link site.ru://endpoint/autocomplete/ by type, but it didn’t work by itself, as I understand it, there should also be something there, or maybe the logic is different. I don't understand JS.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question