我正在尝试从LocationCollection中的数据渲染谷歌地图。 用户将在模型中定义filterParameters,这里是过滤器的JSON
var filter = {
"id_ref_type_category":[2,4],
"pricemin":5,
"pricemax":15,
"distmin":10, // meters
"distmax":150 // meters
}
我需要查询我的收藏,这里是我的位置的json样本
var location = [
{
"id":"1",
"name":"Sushi 1",
"price_min":"10",
"price_max":"20",
"price_avg":"15",
"id_ref_type_category":"1",
"latitude":"48.863831",
"longitude":"2.356215"
},
{
"id":"2",
"description":"Miam ",
"price_min":"15",
"price_max":"35",
"price_avg":"25",
"id_ref_type_category":"4",
"latitude":"48.864269",
"longitude":"2.355153"
},
{
"id":"3",
"name":"Restaurant 1",
"price_min":"5",
"price_max":"20",
"price_avg":"12.5",
"street_number":"60",
"id_ref_type_category":"1",
"latitude":"48.863407",
"longitude":"2.350938"
},
{
"id":"4",
"name":"Chez gigi",
"price_min":"0",
"price_max":"17",
"price_avg":"8.5",
"id_ref_type_category":"2",
"latitude":"48.861824",
"longitude":"2.350901"
}
]
关于我的过滤器参数,我正在寻找
我可以通过地理编码http://www.geodatasource.com/developers/javascript来计算从我的位置到该位置的距离{{3}}
我已经找了主干收集过滤,但没找到很多,我找了json查询系统,但找不到任何东西。
我接受了任何建议。
答案 0 :(得分:1)
如何为所有属性应用下划线过滤器,如下所示:
我放松了一下你的过滤器对象,以便一个位置通过。
基本上过滤器看起来像这样:
var filtered = loc.filter(function (el) {
var dist = distance(el.get('latitude'), el.get('longitude'),
position.latitude, position.longitude, 'K') / 1000;
return ((el.get('id') == filter.id_ref_type_category[0]) ||
(el.get('id') == filter.id_ref_type_category[1])) &&
el.get('price_avg') >= filter.pricemin &&
el.get('price_avg') <= filter.pricemax &&
dist >= filter.distmin &&
dist <= filter.distmax;
});