Вот часть скрипта, которая по моему мнению имеет отношение к проблеме:
if(!dealers.length){
$.getJSON("/include/data.php", {
lat: map.getCenter().lat(),
lng : map.getCenter().lng(),
radius: radius,
type: $('#typeSelect').val(),
category: categorySelect
}, function(json){
dealers = json;
if (json == null) {
$("#sidebar").html('Ничего не найдено.');
$('#numberFoundDealers').text('(Найдено: 0)');
return;
}
var counter = 0;
for (i = 0; i < json.length; i++) {
category_count = 0;
if(json[i].lat == null || json[i].lng == null){
continue;
}
var point = new google.maps.LatLng(json[i].lat, json[i].lng);
// console.log("karta sol`");
if(distHaversine(point, center) < radius && fromUser == true){
}else{
if(fromUser == true){continue};
}
if(json[i].country != cur_country && fromUser == false && frommap == false){
continue;
}
if (distHaversine(point, center) < radius || ($('#citySelect').val() == "0" && frommap == false)) {
var canUse = 1;
if(categorySelect[0] != "0")
{
canUse = 0;
for(var j in json[i].categories){
for(var n in categorySelect){
if(json[i].categories[j] == categorySelect[n]){
category_count++;
}
}
if(category_count == categorySelect.length){
canUse = 1;
category_count = 0;
}
}
}
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
json[i].distance = calculateTheDistance(json[i].lat,json[i].lng,map.getCenter().lat(),map.getCenter().lng());
}
if(!canUse)
continue;
canUse = 1;
if(parseInt($('#typeSelect').val()))
{
canUse = 0;
for(j in json[i].types)
if(json[i].types[j] == $('#typeSelect').val())
canUse = 1;
}
if(!canUse)
continue;
counter++;
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
dealers[i].point = point;
locdata.push(json[i]);
}else{
dealers[i].point = point;
locdata.push(json[i]);
//createMarker(point, dealers[i]);
}
}
}
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
locdata.sort(function(a,b){
if(parseFloat(a.distance) < parseFloat(b.distance))
return -1;
if(parseFloat(a.distance) > parseFloat(b.distance))
return 1;
return 0;
});
}
if($('#typeSelect').val()== "2"){
if(locdata.length > 1){
locdata = bdcsort(locdata);
}
}
$.each(locdata,function(_,val){
if(val){
createMarker(val.point, val);
}
});
$('#numberFoundDealers').text('(Найдено: ' + counter + ')');
$("#sidebar").append(side_bar_html);
});
}
if(dealers.length)
{
var counter = 0;
for (i = 0; i < dealers.length; i++) {
category_count = 0;
if(dealers[i].lat == null || dealers[i].lng == null){
continue;
}
var point = new google.maps.LatLng(dealers[i].lat, dealers[i].lng);
if(distHaversine(point, center) < radius && fromUser == true){
}else{
if(fromUser == true){continue};
}
if(dealers[i].country != cur_country && fromUser == false && frommap == false){
continue;
}
if (distHaversine(point, center) < radius || ($('#citySelect').val() == "0" && frommap == false)) {
var canUse = 1;
if(categorySelect[0] != "0")
{
canUse = 0;
for(var j in dealers[i].categories)
for(var n in categorySelect){
if(dealers[i].categories[j] == categorySelect[n]){
category_count++;
}
}
if(category_count == categorySelect.length){
canUse = 1;
category_count = 0;
}
}
if(dealers[i].distance){
delete dealers[i].distance;
}
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
dealers[i].distance = calculateTheDistance(dealers[i].lat,dealers[i].lng,map.getCenter().lat(),map.getCenter().lng());
}
if(!canUse)
continue;
canUse = 1;
if(parseInt($('#typeSelect').val()))
{
canUse = 0;
for(j in dealers[i].types)
if(dealers[i].types[j] == $('#typeSelect').val())
canUse = 1;
}
if(!canUse)
continue;
counter++;
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
dealers[i].point = point;
locdata.push(dealers[i]);
}else{
dealers[i].point = point;
locdata.push(dealers[i]);
//createMarker(point, dealers[i]);
}
}
}
if($('#citySelect').val() != "0" || frommap != false || fromUser == true){
locdata.sort(function(a,b){
if(parseFloat(a.distance) < parseFloat(b.distance))
return -1;
if(parseFloat(a.distance) > parseFloat(b.distance))
return 1;
return 0;
});
}
if($('#typeSelect').val()== "2"){
if(locdata.length > 1){
locdata = bdcsort(locdata);
}
}
$.each(locdata,function(_,val){
if(val){
createMarker(val.point, val);
}
});
$('#numberFoundDealers').text('(Найдено: ' + counter + ')');
$("#sidebar").append(side_bar_html);
}
}
sidebar - это область, в которой выводится список