尝试显示标记的信息窗口时出现以下错误:
E/flutter ( 1712): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(Invalid markerId, showInfoWindow called with invalid markerId, null)
地图和标记显示正确,当我点击它们时,信息窗口也正确显示。但是,我的意图是始终显示两个标记上的信息窗口。目前我只是想在一个标记上显示问题。我一直使用调试器跟踪执行到 java 端的方法通道,但我从未看到传递了一个 null markerId。谢谢你的帮助。
这是我的代码:
onMapCreated(GoogleMapController controller) async {
final double padding = 150.0;
final double width = mediaSize.width - padding;
final double height = mediaSize.height - padding;
// Create map bounds
final bounds = createTargetBounds();
// Build markers title and snippet information for both current location and destination
final NumberFormat fmt = new NumberFormat('0', 'en_ZA');
final startMarkerId = MarkerId('start');
final startMarker = Marker(
markerId: startMarkerId,
position: LatLng(currentLocation.latitude, currentLocation.longitude),
infoWindow: InfoWindow(title: 'You are here')
);
// Determine distance to destination
double distance = await Geolocator().distanceBetween(
bounds.southwest.latitude,
bounds.southwest.longitude,
bounds.northeast.latitude,
bounds.northeast.longitude);
final finishSnippetInfo = 'Approx ${fmt.format(distance)} meters away from you.';
final finishMarkerId = MarkerId('finish');
final finishMarker = Marker(
markerId: finishMarkerId,
position: LatLng(
destination.latitude,
destination.longitude
),
infoWindow: InfoWindow(title: 'Delivery point', snippet: finishSnippetInfo),
icon: await deliveryIcon
);
// Clear and add markers to map
markers.clear();
markers[startMarkerId] = startMarker;
markers[finishMarkerId] = finishMarker;
controller.showMarkerInfoWindow(startMarkerId);
// Determine correct level of zoom
double zoom =
_getBoundsZoomLevel(bounds.northeast, bounds.southwest, width, height);
controller.moveCamera(CameraUpdate.zoomTo(zoom));
callBack();
}