diff --git a/client/html/index.html b/client/html/index.html
index 08a887d..ef56bff 100644
--- a/client/html/index.html
+++ b/client/html/index.html
@@ -83,6 +83,7 @@
Id |
Name |
+ Distance |
Score |
@@ -90,6 +91,7 @@
{{id}} |
{{name}} |
+ {{distance}} km |
{{score}} |
{{/each}}
diff --git a/client/scripts/application.js b/client/scripts/application.js
index 3db6bcb..d386c08 100644
--- a/client/scripts/application.js
+++ b/client/scripts/application.js
@@ -137,8 +137,10 @@
};
if (_ctx.geo) {
- _ctx.query.latitude = _ctx.geo.coords.latitude;
- _ctx.query.longitude = _ctx.geo.coords.longitude;
+ _ctx.query.geo = {
+ latitude: _ctx.geo.coords.latitude,
+ longitude: _ctx.geo.coords.longitude
+ };
}
if (!_.has(_ctx, 'grapher')) {
@@ -231,7 +233,7 @@
var template = Handlebars.compile($('#template').html());
$('#results').empty();
- $('#results').append(template({'results': results}));
+ $('#results').append(template({results: results}));
}
$(document).on({
@@ -246,7 +248,8 @@
ready: function() {
navigator.geolocation.getCurrentPosition(
function(geo) { onReady(geo); },
- function(err) { onReady(null); }
+ function(err) { onReady(null); },
+ {enableHighAccuracy: true}
);
}
});
diff --git a/server/search.js b/server/search.js
index fc72963..a411415 100644
--- a/server/search.js
+++ b/server/search.js
@@ -64,14 +64,20 @@ function countRecords(data, features, minScore) {
return count;
}
-function findRecords(data, features, minScore) {
+function findRecords(data, geo, features, minScore) {
var results = [];
walkMatches(data, features, minScore, function(record, score) {
+ var distance = 0.0;
+ if (geo !== null) {
+ distance = geolib.getDistance(record.geo, geo) / 1000.0;
+ }
+
results.push({
- name: record.name,
- url: 'http://www.tripadvisor.com' + record.relativeUrl,
- score: score,
- id: record.id
+ name: record.name,
+ url: 'http://www.tripadvisor.com' + record.relativeUrl,
+ score: score,
+ distance: distance,
+ id: record.id
});
});
@@ -196,12 +202,16 @@ function getRecords(callback) {
name: row.name,
id: row.id,
relativeUrl: row.url,
- rating: {
+ geo: {
+ latitude: row.latitude,
+ longitude: row.longitude
+ },
+ rating: {
food: row.food,
service: row.service,
value: row.value,
atmosphere: row.atmosphere
- }
+ },
};
});
@@ -233,6 +243,7 @@ function execQuery(query, callback) {
getData(function(data) {
var searchResults = findRecords(
data,
+ query.geo,
query.features,
query.minScore
);
@@ -264,9 +275,9 @@ function execQuery(query, callback) {
}
module.exports = {
- 'loadDb': loadDb,
- 'addKeyword': addKeyword,
- 'removeKeyword': removeKeyword,
- 'getParameters': getParameters,
- 'execQuery': execQuery
+ loadDb: loadDb,
+ addKeyword: addKeyword,
+ removeKeyword: removeKeyword,
+ getParameters: getParameters,
+ execQuery: execQuery
};