如何在Firebase Cloud Firestore中保存地质点?

如何在Firebase Cloud Firestore中保存地质点?,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,在数据库UI中,我可以创建一个类型为geopoint的字段。在提供值之后,它看起来如下所示: location: [1° N, 1° E] { location: new firebase.firestore.GeoPoint(latitude, longitude) } 我试图通过客户端SDK(web)将其保存到DB。 根据Twitter反馈,我尝试了GeoJSON、Coords数组和Coords对象: location: [1, 2]; location: { latitud

在数据库UI中,我可以创建一个类型为
geopoint
的字段。在提供值之后,它看起来如下所示:

location: [1° N, 1° E]
{
  location: new firebase.firestore.GeoPoint(latitude, longitude)
}
我试图通过客户端SDK(web)将其保存到DB。 根据Twitter反馈,我尝试了GeoJSON、Coords数组和Coords对象:

location: [1, 2];
location: {
    latitude: 1,
    longitude: 2,
};
location: {
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [125.6, 10.1]
    }
}
所有这些都不会导致数据库中的地质点类型。它们只是保存为对象/数组


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

Firestore SDK包含一个,因此您必须保存如下位置:

location: [1° N, 1° E]
{
  location: new firebase.firestore.GeoPoint(latitude, longitude)
}
只需使用:

import 'package:cloud_firestore/cloud_firestore.dart';
{
  location:GeoPoint(latitude, longitude)
}

我努力寻找正确的进口/需求。这就是我的工作

const firebaseAdmin = require('firebase-admin');
//other code ....

//assigning value to myLocation attribute
let newObject = {
    otherAttribute:"otherAttributeValue",
    myLocation: new firebaseAdmin.firestore.GeoPoint(latitude,longitude)
}
对于使用“google/CloudFireStore”包的PHP

您必须使用此类
Google\Cloud\Core\GeoPoint

例如:

<?php

$geoPoint = new \Google\Cloud\Core\GeoPoint($latitude , $longitude);
$data = ['geopoint' => $geoPoint];

您导入了什么来获取GeoPoint类?我尝试了firebase和firebase/应用程序,但没有成功。我在firebase管理员应用程序中。@neonguru-您是否已更新到最新的管理员SDK?它应该在那里@Scarygami-谢谢,这就解释了。我有最新的,但我需要使用firebase admin的导入变量。再次感谢!WebStorm自动从firebase/app使用它。@neonguru你能举个例子吗?我也遇到了同样的问题。到目前为止,不需要
firebase管理员
;只需使用
firebase