Help us understand the problem. What is going on with this article?

【firestore】 Cloud Functions for FirebaseからFire Storeへデータ追加する~位置情報(GeoPoint)編~

今開発中のアプリの中でfirestoreにGeoPoint型のデータを追加する処理を書く機会があったので、忘備録も兼ねて記載。

Cloud FunctionsでFire StoreにGeoPoint型のデータ追加を行う

GeoPointクラスに関するFirebase公式ドキュメントはこちら
(日本語のリファレンスはまだないみたいですね...)

サンプルコード

今回はサンプルコードとして梅田駅の位置情報をfirestoreに追加するファンクションを書いてみます。

index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var fireStore = admin.firestore();

  exports.insertHotelRoom = functions.region('asia-northeast1').https.onRequest((request, response) => {
    var dataRef = fireStore.collection('Stations');
    var data ={
        Address:'大阪府大阪市北区梅田1-1-1',
        Area:'梅田',
        Location:  new admin.firestore.GeoPoint(34.421740, 135.295420),
        Name: 'UMEDA STATION'
    }
    // Add a new document with a generated id.
    dataRef.add({
        data
    }).then(ref => {
        console.log('Added document with ID: ', ref.id);
    }).catch(err =>{
        response.send('ERROR HAPPENED.'+err)
    });
  })

簡単ですが、以上になります。
シンプルにnew admin.firestore.GeoPoint(緯度,経度)でGeoPointの設定ができるみたいですね。
参考になれば幸いです。

参考にした記事

本記事を書くにあたって(というよりもCloud FunctionsからFire Storeを参照する処理について)以下の記事を参考にさせていただきました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away