从 Firebase 检索 GoogleMap 视口内的位置 (LatLng)
Retrieving Locations(LatLng) Inside GoogleMap Viewport from Firebase
如果我要实现从 mySQL
数据库中获取给定视口内的 latlng 列表,我将查询类似 SELECT * FROM places WHERE lat>=$east && lat<=$west && lng>=south && lng<=north
的内容
我想知道我们如何才能在 Firebase 中高效地做类似的事情?
示例结构,
-lats
---12.34567
---23.45678
-lngs
---12.34567
---23.45678
我正在考虑检索每个节点,然后在客户端比较它们的每个 children。
for(double lat: lats){
if(lat >= east && lat <= west){
myLats.add(lat);
}
}
for(double lng: lngs){
if(lng >= south && lng <= north){
myLngs.add(lngs);
}
}
我认为如果我们有 1000 children 来自 lat 和 1000 children 来自 lng.
不知道有没有比这更好的方法?
Firebase 数据库查询只能在单个条件下查询。所以通常不可能查询位置,因为这需要同时过滤纬度和经度。
幸运的是有一个库叫做 GeoFire, which (through the magic of geo-hashes) allows running geo-queries against the Firebase Database. A sample geo-query from the documentation:
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);
我建议您查看 GeoFire for Java。
如果我要实现从 mySQL
数据库中获取给定视口内的 latlng 列表,我将查询类似 SELECT * FROM places WHERE lat>=$east && lat<=$west && lng>=south && lng<=north
我想知道我们如何才能在 Firebase 中高效地做类似的事情?
示例结构,
-lats
---12.34567
---23.45678
-lngs
---12.34567
---23.45678
我正在考虑检索每个节点,然后在客户端比较它们的每个 children。
for(double lat: lats){
if(lat >= east && lat <= west){
myLats.add(lat);
}
}
for(double lng: lngs){
if(lng >= south && lng <= north){
myLngs.add(lngs);
}
}
我认为如果我们有 1000 children 来自 lat 和 1000 children 来自 lng.
不知道有没有比这更好的方法?
Firebase 数据库查询只能在单个条件下查询。所以通常不可能查询位置,因为这需要同时过滤纬度和经度。
幸运的是有一个库叫做 GeoFire, which (through the magic of geo-hashes) allows running geo-queries against the Firebase Database. A sample geo-query from the documentation:
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);
我建议您查看 GeoFire for Java。