GeoFlutterFire
GeoFlutterFire copied to clipboard
How to get/read a GeoFirePoint from a DocumentSnapshot
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?
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.
Any update on this ? There should be helper method fromJSON which should parse MAP type
Having the same issue. Is there a fix planned ?
I added some Dart Extension Methods in the meantime.
@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);