Display distance to restaraunt in results
This commit is contained in:
parent
c7de890a8f
commit
51cafdf034
@ -83,6 +83,7 @@
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>Distance</th>
|
||||
<th>Score</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -90,6 +91,7 @@
|
||||
<tr>
|
||||
<td>{{id}}</td>
|
||||
<td><a href="{{url}}">{{name}}</a></td>
|
||||
<th>{{distance}} km</th>
|
||||
<td>{{score}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
@ -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}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user