我很难理解GeoFire如何查询附近的位置;
我正在构建一个基于地理位置的应用,它将根据用户位置获取附近的位置.我的数据结构如下
locations
-Ke1uhoT3gpHR_VsehIv
-Kdrel2Z_xWI280XNfGg
-name: "place 1"
-description: "desc 1"
geofire
-Ke1uhoT3gpHR_VsehIv
-Kdrel2Z_xWI280XNfGg
-g: "dr5regw90s"
-l
-0: 40.7127837
-1: -74.00594130000002
Run Code Online (Sandbox Code Playgroud)
我似乎无法理解" 跟踪键 "和离开和进入GeoQueries的位置的整个想法.(也许这个概念与优步类功能更相关)
假设locations上面就在附近,我究竟会用自己的lat和long坐标来获取它们?我确定我误解了GeoFires文档,但我只是没有看到它.
我正在尝试在我的Angular2(RC5)应用程序中设置GeoFire.我已经用npm安装了geofire和firebase,并配置了systemjs来导入它.这是我的package.json:
{
"name": "MyProject",
"version": "0.1.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "^2.0.0-rc.5",
"@angular/compiler": "^2.0.0-rc.5",
"@angular/core": "^2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "^2.0.0-rc.5",
"@angular/platform-browser-dynamic": "^2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.5",
"angular2-in-memory-web-api": "0.0.15",
"bootstrap": "^3.3.6",
"core-js": "^2.4.0",
"firebase": "^3.3.0",
"geofire": "^4.1.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": …Run Code Online (Sandbox Code Playgroud) 在我的云函数index.js文件中,我有以下函数体:
exports.onSuggestionCreated = functions.firestore.document('suggestions/{userId}').onCreate(event => {
return admin.firestore().doc(`places/settings/profile`).get().then(doc => {
[...]
const location = data.location
const ref = admin.database().ref(`suggestion_locations`)
const geoFire = new GeoFire(ref)
var geoQuery = geoFire.query({
center: [location.latitude, location.longitude],
radius: 1.0
})
geoQuery.on("key_entered", function(key, location, distance) {
return sendMessageTo(key, title, body)
})
})
})
Run Code Online (Sandbox Code Playgroud)
这是在创建某些内容时触发的函数内部。
我想知道的是,GeoFire即使云功能早已终止,每次有东西进入由位置和半径分隔的区域时,是否都会调用“key_entered” ?我得到了一些表明如此的奇怪日志。
鉴于 的异步性质GeoFire,在这种情况下我能做什么?
我知道这是一个基本问题,但我\xe2\x80\x99m 仍然遇到很多麻烦。
\n\n我有一个 Firebase 数据库存储社区事件。每个事件节点都有一个名为eventPlace的地理位置节点(使用 GeoFire 创建)(请参见下面的屏幕截图)。
\n\n使用 GeoFire(和 javascript),我将如何查询整个数据库并获取特定位置/半径内的所有事件?考虑到数据的存储方式,这可能吗?或者我是否需要将所有位置节点移动到公共节点(eventPlaces?)并查询该单个父节点?
\n\n请注意,我不是在寻求实时数据。这些位置之前已存储,并且不会经常更改。
\n\n预先感谢\xe2\x80\xa6
\n\n\n我对尝试在浏览器代码中使用 geofire-common 感到有点困惑。
一开始,我对 NodeJS 进行了成功的尝试,它使用了Google 文档中geofire-common引用的内容,其代码如下所示:
import { createRequire } from 'module'; // <------ trick to get a require function
const require = createRequire(import.meta.url);
const { initializeApp, cert } = require('firebase-admin/app');
const { getFirestore } = require('firebase-admin/firestore');
const serviceAccount = require('./serviceAccountKey.json');
initializeApp({
credential: cert(serviceAccount),
});
const db = getFirestore();
const geofire = require('geofire-common'); //<---------- geofire-common
Run Code Online (Sandbox Code Playgroud)
然后,我想从浏览器端完成这项工作......我偶然发现了这个例子。在这个例子中,我可以看到一个“require”函数,所以我猜它与老式的 commonJS 模块有关:
const geofire = require('geofire-common');
Run Code Online (Sandbox Code Playgroud)
Require不是标准 JavaScript API 的一部分,应该是 NodeJS 特定的(这有点奇怪,因为我认为这个例子是浏览器代码),所以我尝试使用 ES6 导入。
import {geofire} from …Run Code Online (Sandbox Code Playgroud) 这是 Swift、Firebase 和 Geofire 的问题。
我想知道如何在 Swift 中删除以下观察者的 GeoFire 句柄。
locationsEnd!.query(at: location, withRadius: 16.0).observe(GFEventType.init(rawValue: 0)!, with: {(key, location) in
Run Code Online (Sandbox Code Playgroud)
以下工作正常(在 viewDidDisappear 中):
locationsEnd?.firebaseRef.removeAllObservers()
Run Code Online (Sandbox Code Playgroud)
然而,对于句柄来说,它不会:
var locationHandle: UInt = 0
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
//following does not work:
locationsEnd?.firebaseRef.removeObserver(withHandle: locationHandle)
}
func aroundMe(_ location: CLLocation){
locationHandle = locationsEnd!.query(at: location, withRadius: 16.0).observe(GFEventType.init(rawValue: 0)!, with: {(key, location) in
//etc
})
}
Run Code Online (Sandbox Code Playgroud)
我尝试了如下locationHandle,但没有成功:
var locationHandle = FirebaseHandle()
var locationHandle: FirebaseHandle = 0
var locationHandle: UInt!
var locationHandle: UInt = 0
var …Run Code Online (Sandbox Code Playgroud) 目前,我正在使用 GeoFirebase 库的部分内容以及 Firestore 来进行地理查询。当我设置帖子的 geohash 时,我是这样做的if let geoHash = GFGeoHash(location: location.coordinate).geoHashValue {
但是,为了使 geohash 查询不那么具体,我计划在查询时截断部分 geohash;目前,查询看起来与此类似
var geoQuerySpecific = GFGeoHashQuery()
let geoQueryHash = GFGeoHashQuery.queries(forLocation: (lastLocation?.coordinate)!, radius: (30)) as! Set<GFGeoHashQuery>
for query in geoQueryHash {
geoQuerySpecific = query
print("the key is this um \(geoQuerySpecific)")
}
print("the starting value is \(geoQuerySpecific.startValue) and the end value is \(geoQuerySpecific.endValue)")
let nearQuery = Firestore.firestore().collection("stuff").order(by: "g").whereField("g", isGreaterThanOrEqualTo: geoQuerySpecific.startValue).whereField("g", isLessThanOrEqualTo: geoQuerySpecific.endValue)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这将无法正常工作,因为 geoQueryHash 中有多个项目。当我在 firebase 中设置 geohash 时,我考虑过截断 geohash 的最后四位数字/字母,但是,这还不够具体。为了获得最接近的帖子,最好像我现在一样在数据库中设置 geoHashes,然后,在检索内容时,将起始值设置为查询的最具体的 geohash,然后将最终值设置为截断版本geohash,从获取最近的帖子开始并以最广泛的帖子结束?
我可以将 Firestore …
geolocation geohashing geofire google-cloud-firestore geofirestore
当我在我的 gradle 中添加以下依赖项时:
...
implementation 'com.github.imperiumlabs:GeoFirestore-Android:v1.5.0'
}
Run Code Online (Sandbox Code Playgroud)
我得到:
ERROR: Failed to resolve: com.github.imperiumlabs:GeoFirestore-Android:v1.5.0
Show in Project Structure dialog
Affected Modules: app
Run Code Online (Sandbox Code Playgroud)
我尝试安装以前的版本 (1.4.0),但遇到了同样的错误。
有没有办法解决?
我正在使用 Swift 构建一个 iOS 来共享位置。有谁知道如何使用 Geofire 与 Swift 来存储一个模拟器中的位置,然后在另一个模拟器中显示存储的位置?
多谢。
geofire ×9
firebase ×5
node.js ×3
javascript ×2
swift ×2
android ×1
angular ×1
geofirestore ×1
geohashing ×1
geolocation ×1
gradle ×1
ios ×1
systemjs ×1
vite ×1