google_maps_flutter
有没有办法以编程方式显示/隐藏InfoWindow?也许是“selecting”一个标记?
当我将摄像机移动到不同的标记时,仍会选择上一个标记,因此Infowindow不会更新。
我尝试空InfoWindow属性,设置为空字符串等尝试失败。
我有下面的代码来选择一个标记。当用户点击Map上的一个标记时,这可以完美地工作。但是当你试图通过代码导航到Map上的一个标记时(例如调用selectMarker),我找不到一种方法来以编程方式显示点击的标记的InfoWindow(并将其隐藏在先前选择的标记上)。
void **selectMarker**(String markerId, bool requiresCameraPositioning) async {
var previouslySelectedMarker = _localSelectedMarkerId;
print ('x: method:selectMarker, markerId:${markerId}, requiresCameraPositioning${requiresCameraPositioning}, localSelectedMarkerId:${_localSelectedMarkerId}, requiresCameraPositioning${requiresCameraPositioning}');
// Unselect the previously selected marker
_localSelectedMarkerId = markerId;
final markerItem = markerController.markers.firstWhere(
(marker) => marker.id == markerId,
orElse: () => throw Exception('Marker not found'),
);
if (requiresCameraPositioning) {
mapControllerManager.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(markerItem.position.latitude, markerItem.position.longitude),
zoom: 15,
),
),
);
}
_updateMarkerIcons(); // Refresh markers to reflect the selection
var selectedMarker = _markers.firstWhere((element) => element.markerId == _localSelectedMarkerId);
// show modal
_showModalBottomSheet(context, markerId);
字符串
}
public void setState(){
Set<Marker> updatedMarkers = {};
for (var markerItem in markerController.markers) {
bool isSelected = markerItem.id == _localSelectedMarkerId;
updatedMarkers.add(
Marker(
markerId: MarkerId(markerItem.id),
position: markerItem.position,
**infoWindow: InfoWindow(title: markerItem.title),** I have tried multiple things here
icon: determineMarkerIcon(markerItem),
onTap: () {
selectMarker(markerItem.id, false); // Call _selectMarker here instead
},
),
);
}
_markers = updatedMarkers;
});
型
}
1条答案
按热度按时间vkc1a9a21#
如果有人遇到同样的问题,我不知何故找到了这个相关的帖子Programmatically Select Marker to Navigate To Location Google_Maps_Flutter
也就是说有人有同样的问题。我会给予一个机会。