Pro*_*mit 25 firebase google-cloud-firestore
在数据库UI中,我可以创建一个具有该类型的字段geopoint.提供值后,它看起来像这样:
location: [1° N, 1° E]
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过客户端SDK(Web)将其保存到数据库中.基于Twitter反馈我尝试了GeoJSON,Coords数组和Coords对象:
location: [1, 2];
location: {
latitude: 1,
longitude: 2,
};
location: {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
}
}
Run Code Online (Sandbox Code Playgroud)
这些都不会导致数据库中的geopoint类型.它们只是保存为对象/数组.
如何通过Web SDK在Firebase Cloud Firestore中保存GeoPoint?
Sca*_*ami 50
Firestore SDK包含a GeoPoint class,因此您必须保存以下位置:
{
location: new firebase.firestore.GeoPoint(latitude, longitude)
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我努力找出正确的导入/要求。这对我有用!!
const firebaseAdmin = require('firebase-admin');
//other code ....
//assigning value to myLocation attribute
let newObject = {
otherAttribute:"otherAttributeValue",
myLocation: new firebaseAdmin.firestore.GeoPoint(latitude,longitude)
}
Run Code Online (Sandbox Code Playgroud)
只需使用:
import 'package:cloud_firestore/cloud_firestore.dart';
{
location:GeoPoint(latitude, longitude)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16087 次 |
| 最近记录: |