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]
For PHP using "google/cloud-firestore" package
you have to use this class Google\Cloud\Core\GeoPoint
example:
<?php
$geoPoint = new \Google\Cloud\Core\GeoPoint($latitude , $longitude);
$data = ['geopoint' => $geoPoint];
I struggled to find out the right import/require. This is what worked for me !!
const firebaseAdmin = require('firebase-admin');
//other code ....
//assigning value to myLocation attribute
let newObject = {
otherAttribute:"otherAttributeValue",
myLocation: new firebaseAdmin.firestore.GeoPoint(latitude,longitude)
}
The Firestore SDKs include a GeoPoint class, so you would have to save locations like this:
{
location: new firebase.firestore.GeoPoint(latitude, longitude)
}
Simply use:
import 'package:cloud_firestore/cloud_firestore.dart';
{
location:GeoPoint(latitude, longitude)
}