我有一个 firebase 函数,通过 geohash 搜索半径执行查询和过滤。它正在工作,但我正在返回 Json,而我真正想做的是返回一个快照。我是 Firebase 功能的新手。
这是我的火力基地功能
var GeoFirestore = require('geofirestore').GeoFirestore;
exports.geoQueryWitningRadius = functions.https.onRequest(async (req, res) => {
const data = req.body;
const lat = data.lat;
const lon = data.lon;
const radius = data.radius;
const firestore = admin.firestore();
const geofirestore = new GeoFirestore(firestore);
const geocollection = geofirestore.collection('pickups');
const query = geocollection.near({ center: new admin.firestore.GeoPoint(lat, lon), radius:
radius });
await query.get().then((snapshot) => {
return res.send(snapshot)
}).catch(error => {
console.log('error', error);
});
});
这是我在 swift 中的 http 请求
static func getGeoHashPickups(radius: Int, completion: @escaping([String: Any]?, String?) -> Void) { //url, Error
let parameters : [String : Any] = [
"lat" : UserService.user.lat,
"lon" : UserService.user.lon,
"radius" : radius
]
let url = "https://us-central1-app-request-ect"
AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: [:]).responseJSON { response in
switch response.result {
case .success(let dict):
guard let dictionary = dict as? [String : Any] else { return }
completion(dictionary, nil)
case .failure(let error):
print(error.localizedDescription)
completion(nil, error.localizedDescription)
}
}
}
如何将返回到前端的内容转换为快照?