本文介绍了如何在Firebase Cloud Firestore中保存GeoPoint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库UI中,我可以创建类型为geopoint的字段.提供值后,看起来像这样:

location: [1° N, 1° E]

我正在尝试通过客户端SDK(网络)将其保存到数据库中.根据Twitter反馈,我尝试了GeoJSON,Coords Array和Coords Object:

location: [1, 2];
location: {
    latitude: 1,
    longitude: 2,
};
location: {
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [125.6, 10.1]
    }
}

没有一个导致数据库中的geopoint类型.它们只是保存为对象/数组.

如何通过Web SDK在Firebase Cloud Firestore中保存GeoPoint?

解决方案

Firestore SDK包含 GeoPoint class ,因此您必须保存以下位置:

{
  location: new firebase.firestore.GeoPoint(latitude, longitude)
}

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]

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.

How to save GeoPoint in Firebase Cloud Firestore via the Web SDK?

解决方案

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:29