Search code examples
google-mapsflutterdartpolylinegoogle-polyline

Flutter - Polyline Not drawing line inside Available screen size


How can I get polyline inside available screensize?

I'm using Flutter Goolge Map Plugin , Google Map Polyline Plugin

Polyline drawing outside screensize


Solution

  • First of all polylines added are placed wrong. you can follow my answer to generate then correctlly : https://stackoverflow.com/a/58831792/7910735

    And for your Question you should use CameraUpdate.newLatLngBounds() just after placing the polylines.

    Somewhat similiar to this

    void animateCameraForOD() {
        mapController.animateCamera(
          CameraUpdate.newLatLngBounds(
              LatLngBounds(
                    southwest: LatLng(
                        fromLocationLatLng.latitude <= toLocationLatLng.latitude
                            ? fromLocationLatLng.latitude
                            : toLocationLatLng.latitude,
                        fromLocationLatLng.longitude <= toLocationLatLng.longitude
                            ? fromLocationLatLng.longitude
                            : toLocationLatLng.longitude),
                    northeast: LatLng(
                        fromLocationLatLng.latitude <= toLocationLatLng.latitude
                            ? toLocationLatLng.latitude
                            : fromLocationLatLng.latitude,
                        fromLocationLatLng.longitude <= toLocationLatLng.longitude
                            ? toLocationLatLng.longitude
                            : fromLocationLatLng.longitude)),100),
        );
      }
    

    It will make your both LatLngs to be zoomed out to be in the given bounds with padding also.