Skip to content

Commit

Permalink
Faccio il sorting per le coordinate solo se possibile
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdi2005 committed Sep 14, 2021
1 parent 6e3602e commit a94b211
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/controllers/home/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function setMonumentsData(response, user_initiated, located = false, location){
response.forEach(function (item) {
var title;
// Ottengo la distanza tra elementi
if (located == true && item.latitude != null && item.longitude != null) {
if (located && item.latitude != null && item.longitude != null) {
title = item.itemlabel + " (" + getDistance(location.coords.latitude, location.coords.longitude, item.latitude, item.longitude) + " km)";
} else {
title = item.itemlabel;
Expand All @@ -45,9 +45,11 @@ function setMonumentsData(response, user_initiated, located = false, location){
});

if ($.listsection.items != data) {
data = data.sort(function(a,b){
return getDistance(location.coords.latitude, location.coords.longitude, a.properties.latitude, a.properties.longitude) - getDistance(location.coords.latitude, location.coords.longitude, b.properties.latitude, b.properties.longitude);
})
if (located) {
data = data.sort(function(a,b){
return getDistance(location.coords.latitude, location.coords.longitude, a.properties.latitude, a.properties.longitude) - getDistance(location.coords.latitude, location.coords.longitude, b.properties.latitude, b.properties.longitude);
})
}
$.listsection.setItems(data);
}
$.listview.show();
Expand Down

0 comments on commit a94b211

Please sign in to comment.