GeoFlutterFire icon indicating copy to clipboard operation
GeoFlutterFire copied to clipboard

How to get/read a GeoFirePoint from a DocumentSnapshot

Open awhitford opened this issue 6 years ago • 5 comments

Where point is a GeoFirePoint instance, I was successful at writing the point to the database with something like:

    doc.reference.updateData({'geoLocation': point.data});

But now I am unable to read the point back (where doc is a DocumentSnapshot):

    final GeoFirePoint point = doc["geoLocation"];

It said:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'GeoFirePoint'

What am I missing?

awhitford avatar May 05 '19 00:05 awhitford

So this is what I figured out I needed to do...

final GeoFirePoint point = GeoFirePoint(
        doc["geoLocation"]["geopoint"].latitude,
        doc["geoLocation"]["geopoint"].longitude);

This seems to work, but I'd prefer to see GeoFirePoint treated like an opaque type, similar to GeoPoint.

A constructor for GeoFirePoint based on a GeoPoint value would be better, then it could be:

final GeoFirePoint point = GeoFirePoint.fromGeoPoint(doc["geoLocation"]["geopoint"]);

However, this is still not ideal because it expects the user to understand how GeoFirePoint is stored.

awhitford avatar May 05 '19 00:05 awhitford

Any update on this ? There should be helper method fromJSON which should parse MAP type

rdev-software avatar May 16 '19 22:05 rdev-software

Having the same issue. Is there a fix planned ?

elvisgn avatar Nov 07 '19 13:11 elvisgn

I added some Dart Extension Methods in the meantime.

awhitford avatar Mar 18 '20 15:03 awhitford

@awhitford looks like this is a breaking change.

This no longer works

    Position position = await Geolocator()
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

    GeoFirePoint point = geo.point( position.latitude,  position.longitude);

instead you need to provide keys


    Position position = await Geolocator()
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

    GeoFirePoint point = geo.point(latitude: position.latitude, longitude: position.longitude);

giorgio79 avatar May 14 '20 02:05 giorgio79