geofirex icon indicating copy to clipboard operation
geofirex copied to clipboard

Firestore GeoPoint latitude and longitude errors

Open lucapale opened this issue 4 years ago • 2 comments

Hi, I have noticed that in my app the GeoPoint is stored as: {Wa:number, za:number} instead of latitude and longitude as used in your code. I have modified the "filter" inside the "within" function as follows: var _a = val[field].geopoint, latitude = _a.latitude ? _a.latitude : _a.Wa, longitude = _a.longitude ? _a.longitude :_a.za;

With this is works. Bye Luca

lucapale avatar Apr 07 '20 15:04 lucapale

@lucapale can you explain in more detail where you put this?

I also have the problem, that the point object is stored differently in some cases. The pattern I can see on my side so far is that this happens when the created object is set to firestore through a transaction.

Then the object looks like this and I cannot query it with the proposed within query from the documentation:

image

StevieWag avatar Jul 31 '20 05:07 StevieWag

I have noticed that Firebase stored the information in this way because I was converting all the data to JSON before writing it (i.e. JSON.parse(JSON.stringify(object)) ). This because Firebase does not accept classes which are not known. Now I keep at least the geolocation information as class inside the object and Firebase stores it in the correct way. For the previous data I have made a function which converts again the stored object into a Geopoint, before making the query.

lucapale avatar Jul 31 '20 08:07 lucapale