DarshanGowda0 / GeoFlutterFire

:fire:GeoFlutterFire:fire: is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://youtu.be/MYHVyl-juUk
MIT License
305 stars 260 forks source link

How to get/read a GeoFirePoint from a DocumentSnapshot #38

Open awhitford opened 5 years ago

awhitford commented 5 years ago

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 commented 5 years ago

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.

rdev-software commented 5 years ago

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

elvisgn commented 5 years ago

Having the same issue. Is there a fix planned ?

awhitford commented 4 years ago

I added some Dart Extension Methods in the meantime.

giorgio79 commented 4 years ago

@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);