Permalink
Browse files

done with sorting# with '#' will be ignored, and an empty message abo…

…rts the commit.
  • Loading branch information...
Michael Shapiro
Michael Shapiro committed Jul 7, 2010
1 parent 0b0404d commit 55e0a799d51cd3de4a2b8b9392fee7eeb732da00
Showing with 25 additions and 6 deletions.
  1. +3 −2 war/index.jsp
  2. +22 −4 war/js/index.js
View
@@ -222,8 +222,9 @@ if (!searchresults){
}
String GEOCODE_API_URL = "http://maps.google.com/maps/api/geocode/json?latlng=" + Lat + "," + Lon +"&sensor=true";
APIresponse = sg.submitURL(GEOCODE_API_URL);
-
- %>var geocode = <%=APIresponse.getBody().toString()%>
+ %>User_Lat = <%=Lat + ";\n"%>
+ User_Lon = <%=Lon + ";\n"%>
+ var geocode = <%=APIresponse.getBody().toString()%>
var location = 'Events near ' + geocode.results[0].address_components[2].long_name;
$('#searchResultsHeading').append(location);
View
@@ -6,11 +6,25 @@
var current_page = 1;
var events_per_page = 5;
var d = new Date();
-
+ var User_Lat = 0;
+ var User_Lon = 0;
+
+ //distance between two points
+ function distance(lat1, lon1, lat2, lon2) {
+ var R = 6371; // km
+ var dLat = (lat2-lat1)*(Math.PI / 180);
+ var dLon = (lon2-lon1)*(Math.PI / 180);
+ var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
+ Math.cos(lat1) * Math.cos(lat2) *
+ Math.sin(dLon/2) * Math.sin(dLon/2);
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+ var d = R * c * 0.621371192;
+ return d
+ }
//event sorting functions
function SortByRSVP(a, b){
- alert(a.ev.rsvp_count);
+ //alert(a.ev.rsvp_count);
if (a.ev.rsvp_count < b.ev.rsvp_count) {
return 1;
} else {
@@ -28,7 +42,11 @@
}
function SortByDistance(a, b){
-
+ if (distance(User_Lat, User_Lon, a.ev.lat, a.ev.lon) > distance(User_Lat, User_Lon, b.ev.lat, b.ev.lon)){
+ return 1;
+ } else {
+ return -1;
+ }
}
//set description to any string
@@ -215,7 +233,7 @@
eventArray.push(event_object);
}
});
- eventArray.sort(SortByRSVP);
+
update_events(current_page);

0 comments on commit 55e0a79

Please sign in to comment.