UNPKG

900 BJavaScriptView Raw
1
2/**
3 And example of a reverse geocoding query to match and return
4 the nearest record to our focus point.
5**/
6
7// this is our focus point (somewhere in London)
8var focus = { lat: 51.5, lon: -0.06 };
9
10var query = require('../index'),
11 vs = new query.Vars( query.defaults );
12
13/**
14 build a query with 2 conditions:
15 - (optional) geographic bounds
16 - sort results by distance
17**/
18var q = new query.layout.FilteredBooleanQuery()
19 .filter( query.view.boundary_circle )
20 .sort( query.view.sort_distance );
21
22// we only want 1 result
23vs.var('size', 1);
24
25// set bounding variables
26vs.set({
27 'boundary:circle:lat': focus.lat,
28 'boundary:circle:lon': focus.lon,
29 'boundary:circle:radius': '5km'
30});
31
32// set focus point
33vs.set({
34 'focus:point:lat': focus.lat,
35 'focus:point:lon': focus.lon
36});
37
38// render the query
39var rendered = q.render( vs );
40console.log( JSON.stringify( rendered, null, 2 ) );
\No newline at end of file