Firebase Cloud Firestore에서 GeoPoint를 저장하는 방법은 무엇입니까?
데이터베이스 UI에서 유형을 사용하여 필드를 생성할 수 있습니다.geopoint
값을 제공한 후에는 다음과 같이 표시됩니다.
location: [1° N, 1° E]
클라이언트 측 SDK(웹)를 통해 DB에 저장하려고 합니다.트위터 피드백을 기반으로 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]
}
}
데이터베이스에 지정점 유형이 지정되지 않았습니다.개체/어레이로 저장됩니다.
웹 SDK를 통해 Firebase Cloud Firestore에 GeoPoint를 저장하는 방법은 무엇입니까?
Firestore SDK에는 다음과 같은 위치를 저장해야 합니다.
{
location: new firebase.firestore.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)
}
간단히 사용:
import 'package:cloud_firestore/cloud_firestore.dart';
{
location:GeoPoint(latitude, longitude)
}
버전 9 소방서
import { GeoPoint} from "firebase/firestore";
const dataDocument = {
tienda: new GeoPoint(latitude: number, longitude: number),
}
유형 스크립트에서 다음 코드를 사용할 수 있습니다.firebase-admin
sdk,
import { GeoPoint } from "firebase-admin/firestore";
const geoPoint = new GeoPoint(latitude, longitude)
이것은 을 위한 것입니다."firebase-admin": "11.2.0"
라이브러리 버전입니다.
또한 다음 사항을 확인합니다.latitude
안에 있어야 합니다.[-90, 90]
포괄적으로longitude
안에 있어야 합니다.[-180, 180]
포괄적인그렇지 않으면 firebase sdk가 던집니다.Value for argument \"longitude\" must be within [-180, 180] inclusive, but was: 230
웹 SDK의 경우 다음과 같이 가져오기를 업데이트하기만 하면 됩니다.
import { GeoPoint } from "firebase/firestore";
"google/cloud-firestore" 패키지를 사용하는 PHP의 경우
당신은 이 수업을 사용해야 합니다.Google\Cloud\Core\GeoPoint
예:
<?php
$geoPoint = new \Google\Cloud\Core\GeoPoint($latitude , $longitude);
$data = ['geopoint' => $geoPoint];
GeoFirePoint geoFirePoint = geo.point(latitude: lat, longitude: lng);
_firestore
.collection('locations')
.add({'name': 'random name', 'position': geoFirePoint.data}).then((_) {
print('added ${geoFirePoint.hash} successfully');
});
언급URL : https://stackoverflow.com/questions/46603691/how-to-save-geopoint-in-firebase-cloud-firestore
'programing' 카테고리의 다른 글
Vuex 상태 또는 getter는 항상 정의되지 않은 상태를 반환합니다. (0) | 2023.06.13 |
---|---|
다른 빌드 구성표에 다른 Google Service-Info.plist 사용 (0) | 2023.06.13 |
여러 번의 Vuex 변환 구독 트리거 (0) | 2023.06.13 |
오류: c에서 입력 끝에 선언 또는 문이 필요합니다. (0) | 2023.06.13 |
.NET EXE를 읽을 수 있는 C# 소스 코드로 압축 해제하려면 어떻게 해야 합니까? (0) | 2023.06.13 |