在谷歌地图上添加弹出标记



当使用flutter/dart点击或点击时,我如何添加弹出窗口来显示谷歌地图上特定标记的详细信息。我尝试过使用onTap功能,但给了我错误——关于如何实现的任何想法

populateHospitals() {
Hospitals = []; //array to obtain individual hospital data
Firestore.instance.collection('markers').getDocuments().then((docs) {
if (docs.documents.isNotEmpty) {
setState(() {
hospitalsToggle = true;
});
for (int i = 0; i < docs.documents.length; ++i) {
Hospitals.add(docs.documents[i].data);
initMarker(docs.documents[i].data);
}
}
});
}
initMarker(hospitals) {
mapController.clearMarkers().then((val) {
mapController.addMarker(MarkerOptions(
position:
LatLng(hospital['location'].latitude, hospital['location'].longitude),// draws the markers of the hospitals
draggable: false, // disables dragging of the marker
consumeTapEvents: true,
infoWindowText: InfoWindowText(hospital['hospitalname'], 'hospital'), //displays the hospitals name when the icon is clicked
));

});
}

使用以下内容阅读更多源代码https://github.com/flutter/plugins/blob/master/packages/google_maps_flutter/google_maps_flutter/example/lib/place_marker.dart

List <Marker> markers = new List<Marker>();
//Run the loop and add locations to marker 

markers.add(
Marker(
markerId: <SOMEID>,
position: LatLng(hospital['location'].latitude, hospital['location'].longitude),

onTap: () {
//this is what you're looking for!
print(hospital['hospitalname']);

}
)
);
//Now add this to your map.

相关内容

  • 没有找到相关文章

最新更新