Google_maps_flutter exception when calling showMarkerInfoWindow

Viewed 912

I'm getting the following error when trying to display a marker's info window:

E/flutter ( 1712): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(Invalid markerId, showInfoWindow called with invalid markerId, null)

The map and the markers are displayed correctly and when I tap on them the info window is displayed correctly as well. My intention, however, is to have the info windows on both markers displayed all the time. At the moment I'm only trying to display on one marker to show the problem. I followed the execution with the debugger all the way to the method channel on the java side and I never saw a null markerId passed. Thanks for your help.

Here's my code:

  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();
  }
0 Answers
Related