firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.63k stars 371 forks source link

Problems with constructing geopoint using admin.firestore.Geopoint(0, 0) [Firestore] #1215

Closed aponski closed 3 years ago

aponski commented 3 years ago

Describe the problem

In a cloud function I'm constructing geopoint using new admin.firestore.Geopoint(0, 0) and store it in firestore. However it is not properly recognised when viewing in the firestore UI browser. It is shown as simple object {_latitude: 0, _longitude: 0}.

image

When I construct geopoint in a frontend web app using new firebase.firestore.GeoPoint(0, 0) it is shown ok in firestore UI browser as [0° N, 0° E].

image

google-oss-bot commented 3 years ago

I found a few problems with this issue:

schmidt-sebastian commented 3 years ago

Can you share you code? One possibility might that you are using JSON.stringify() before sending the data to the SDK.

aponski commented 3 years ago

I'm using axios to make a request

const payload = {
     geoPoint: new admin.firestore.GeoPoint(latitude, longitude), 
}

const response = await axios(
                {
                    method: 'post',
                    baseURL: baseApiUrl,
                    url: '/address',
                    params: {
                        api_token: apiToken
                    },
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    responseType: 'json',
                    data: paylod
                }
            )
schmidt-sebastian commented 3 years ago

Our types are only supported if you use the Admin SDK to write to the backend. If you are using the REST API, you have to manually serialize your data to the Protobuf REST representation (which can be quite a bit of work).

See details here: https://firebase.google.com/docs/firestore/use-rest-api