invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.64k stars 2.21k forks source link

[FireStore][Android] GeoPoint throwing error, what is the correct usage? #581

Closed rtman closed 6 years ago

rtman commented 6 years ago

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

rtman commented 6 years ago

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)

Ehesp commented 6 years ago

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

vysogot commented 5 years ago

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