How to save GeoPoint in Firebase Cloud Firestore?

后端 未结 4 452
小蘑菇
小蘑菇 2020-12-24 13:01

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]


        
相关标签:
4条回答
  • 2020-12-24 13:11

    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];
    
    0 讨论(0)
  • 2020-12-24 13:14

    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)
    }
    
    0 讨论(0)
  • 2020-12-24 13:33

    The Firestore SDKs include a GeoPoint class, so you would have to save locations like this:

    {
      location: new firebase.firestore.GeoPoint(latitude, longitude)
    }
    
    0 讨论(0)
  • 2020-12-24 13:34

    Simply use:

    import 'package:cloud_firestore/cloud_firestore.dart';
    {
      location:GeoPoint(latitude, longitude)
    }
    
    0 讨论(0)
提交回复
热议问题