Search code examples
google-mapsfluttergoogle-cloud-firestoregeolocation

save LatLng(geopoint) value in firestore document / geolocator package


i am new to flutter and i need to save a value inside my user document. i can print the values but i do not know how to assign the values of LatLan to a variable and get them saved in firestore. here is my searchMapPlaceWidget that returns them values

 SearchMapPlaceWidget(
   darkMode: true,
   placeType: PlaceType.establishment,
   language: 'se',
   apiKey: kGoogleApiKey,
   onSelected: (place) async {
     final geolocation =
       await place.geolocation;

     final chosenPlace = Marker(
       markerId: MarkerId(
         'chosen-location'),
       icon: BitmapDescriptor
       .defaultMarker,
       position:
       geolocation.coordinates);
     GoogleMapController controller =
       await _mapController.future;
     setState(() {
       _markers.add(chosenPlace);
     });
     print(chosenPlace.position);

     controller.animateCamera(
       CameraUpdate.newLatLng(
         geolocation.coordinates));
     controller.animateCamera(
       CameraUpdate.newLatLngBounds(
         geolocation.bounds, 50));
   },

 ),

here is the function that i wrote which is not working 😅

static void addGeoPoint(User user)async{
var pos = await location.getLocation();
GeoFirePoint point = geo.point(latitude: pos.latitude, longitude: pos.longitude);
return usersRef.document(user.id).updateData({
  'myAddress' : point.data
});

}

how do i save the position values of 'chosenPlace' ?

thank you all


Solution

  • solved it.

     GeoFirePoint myLocation = geo.point(latitude: _location.latitude, longitude: _location.longitude);
                                                  usersRef.document(widget.user.id).updateData({
                                                    'position' : myLocation.data