我正在尝试 google maps flutter with firestore 但出了点问题。
这是我的代码
class StoreMap extends StatelessWidget {
const StoreMap({
Key key,
@required this.documents,
@required this.initialPosition,
@required this.mapController,
}) : super(key: key);
final List<DocumentSnapshot> documents;
final LatLng initialPosition;
final Completer<GoogleMapController> mapController;
@override
Widget build(BuildContext context) {
return GoogleMap(
initialCameraPosition: CameraPosition(
target: initialPosition,
zoom: 12,
),
markers: documents
.map((document) => Marker(
markerId: MarkerId(document['placeId']),
icon: BitmapDescriptor.defaultMarkerWithHue(_pinkHue),
position: LatLng(
document['location'].latitude,
document['location'].longitude,
),
infoWindow: InfoWindow(
title: document['name'],
snippet: document['address'],
),
))
.toSet(),
onMapCreated: (mapController) {
this.mapController.complete(mapController);
},
);
}
}
类型“GeoPoint”不是类型“String”的子类型
Firestore 看起来像
最佳答案
问题看起来是MarkerId(document['placeID'])
,它需要是一个字符串。
您可以尝试使用 MarkerId(document['placeID'].toString())
或根据标记的位置生成您自己的自定义字符串。
注意您的 placeId
而不是 placeID
。
关于flutter - 类型 'GeoPoint' 不是 flutter firestore 中类型 'String' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56574178/