React-native-firebase: [FireStore][Android] GeoPoint throwing error, what is the correct usage?

Created on 4 Nov 2017  路  3Comments  路  Source: invertase/react-native-firebase

Hey,

Just trying to get the geoPoint datatype working and I am having trouble. I have tried searching around and found very little information on the correct usage of this.

Here's my code

                navigator.geolocation.getCurrentPosition((position) => {
                    console.log('position', position);
                    this.setState({
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                        coordinates:  firebase.firestore.geoPoint(position.coords.latitude, position.coords.longitude),
                        error: null,
                    });
                    console.log('coordinates', this.state.coordinates);
                  },(error) => this.setState({ error: error.message }),
                  { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
                )

This throws the following error:
_reactNativeFirebase2.default.firestore.geoPoint is not a function

I see that in the firestore docs it is new GeoPoint(latitude, longitude), so I'm wondering if it should be the same in RNFirebase?

Currently what I see in the docs here is firebase.firestore.geoPoint and geoPoint(latitude, longitude); Which is how I got to my current code.

So can someone who knows let me know the proper usage with RNFirebase?

Thanks!

Environment

Application Target Platform:
Android

Development Operating System:
Windows 10

Build Tools:

React Native version:
0.49.3

RNFirebase Version:
3.0.6

Firebase Module:
Cloud Firestore

Most helpful comment

Did something change?

import firebase from '@firebase/app';
require('@firebase/firestore');

const location = new firebase.firestore.GeoPoint(this.state.latitude, this.state.longitude);

This gives me an error:
__WEBPACK_IMPORTED_MODULE_1__firebase__.a.firestore.GeoPoint is not a constructor

Versions:
firebase: ^5.4.2
react: ^16.5.0

All 3 comments

Ok so I got it working.
What works is the following, so the docs should be changed to GeoPoint:
new firebase.firestore.GeoPoint(latitude, longitude)

Ah that's something which changed while Firestore was still being developed. I'll get it updated.!

Did something change?

import firebase from '@firebase/app';
require('@firebase/firestore');

const location = new firebase.firestore.GeoPoint(this.state.latitude, this.state.longitude);

This gives me an error:
__WEBPACK_IMPORTED_MODULE_1__firebase__.a.firestore.GeoPoint is not a constructor

Versions:
firebase: ^5.4.2
react: ^16.5.0

Was this page helpful?
0 / 5 - 0 ratings