将LatLng(地理点)值保存在firestore文档/地理定位器包中



我是flutter新手,需要在用户文档中保存一个值。我可以打印这些值,但我不知道如何将LatLan的值分配给一个变量并将其保存在firestore中。这是我的searchMapPlaceWidget,它返回它们的值

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));
},
),

这是我写的函数,它不起作用😅

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

}

如何保存"chosenPlace"的位置值?

感谢所有

解决了这个问题。

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

最新更新