问题描述
在数据库 UI 中,我可以创建一个类型为 geopoint
的字段.提供值后,它看起来像这样:
in the database UI I can create a field with the type geopoint
. After providing values, it looks something like this:
location: [1° N, 1° E]
我正在尝试通过客户端 SDK (web) 将其保存到数据库中.根据 Twitter 反馈,我尝试了 GeoJSON、Coords Array 和 Coords Object:
I'm trying to save this to the DB via client side SDK (web).Based on Twitter Feedback I tried GeoJSON, Coords Array and Coords Object:
location: [1, 2];
location: {
latitude: 1,
longitude: 2,
};
location: {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
}
}
这些都没有导致数据库中的地理点类型.它们只是保存为对象/数组.
None of which resulted in the geopoint type in the database. They're just saved as Objects/Arrays.
如何通过 Web SDK 在 Firebase Cloud Firestore 中保存 GeoPoint?
How to save GeoPoint in Firebase Cloud Firestore via the Web SDK?
推荐答案
Firestore SDK 包括一个 GeoPoint class
,因此您必须像这样保存位置:
The Firestore SDKs include a GeoPoint class
, so you would have to save locations like this:
{
location: new firebase.firestore.GeoPoint(latitude, longitude)
}
这篇关于如何在 Firebase Cloud Firestore 中保存 GeoPoint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!