-1

I have implemented a screen with GoogleMaps widget and used

final Set<Polyline> _polyline = {};

List<LatLng> latlng = List();

with a sample of

  latlng.add(LatLng(7.2008,79.8737));
  latlng.add(LatLng(7.2018,79.8737));
  latlng.add(LatLng(7.2028,79.8739));
  latlng.add(LatLng(7.2028,79.8707));
  latlng.add(LatLng(7.2008,79.8700));
  latlng.add(LatLng(7.1998,79.8695));

but polylines draws like this

screen shot

and here is the code for google map

    Widget _googlemap(BuildContext context) {
      Size size = MediaQuery.of(context).size;

      return Container(
        height: size.height,
        width: size.width,
        child: GoogleMap(
          compassEnabled: true,
          mapType: MapType.normal,
          myLocationButtonEnabled: true,
          myLocationEnabled: true,
          onMapCreated: (GoogleMapController controller) async {
            _controller.complete(controller);
            final GoogleMapController mapController = await _controller.future;
            Position position = await Geolocator()
                .getLastKnownPosition(desiredAccuracy: LocationAccuracy.high);

            controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
                target: LatLng(position.latitude, position.longitude), zoom: 15)));
          },
          markers: _markers.values.toSet(),
          initialCameraPosition: _initialCameraPosition,
          polylines: _polyline ,
        ),
      );
    }

and I'm expecting a straight line without getting the connected end and start together. I'm glad is someone can help me out, thanks!!

Viroj Fernando
  • 461
  • 4
  • 8

1 Answers1

1

You are using 6 points, not 4 points, so in the "vertical" lines of your "square" you have 3 points. And this is exactly your problem! This 3 points are not linear. If you use just 4 points you will get "straight" lines!

LgFranco
  • 1,004
  • 6
  • 14
  • yes actually those 6 points not linear, but 6th point and 1st point connects each other. I just want to stop the lines from 6 and end there. but it creates a complete shape. not a straight route with relevant turnings or bends in the route. – Viroj Fernando Aug 11 '19 at 02:59