Route polyline not Drawing correctly for Long Distances Google Map

Viewed 18

the polyline is following the Route but it's not accurate only in long distances

this is short distance vs a long one

CLick here to see the image

i am using google_polyline_algorithm package to decode the response i think the problem is in the request parameters my code:

  Dio dio = Dio();
  List<LatLng> polyLineCoordinates = [];
  final response = await dio.get(
    "https://maps.googleapis.com/maps/api/directions/json?",
    queryParameters: {
      'origin':
          '${myLocation.target.latitude},${myLocation.target.longitude}',
      'destination':
          '${orderLocation.target.latitude},${orderLocation.target.longitude}',
      'key': "Google API Key",
      'alternatives': 'false',
      'travelMode':'DRIVE',
      'optimizeWaypointOrder': false,
      'polylineQuality': 'HIGH_QUALITY',
    },

  );
  final lines = decodePolyline(
      response.data["routes"][0]['overview_polyline']['points']);
  lines.forEach((point) {
    polyLineCoordinates
        .add(LatLng(point[0].toDouble(), point[1].toDouble()));
  });

widget code:

GoogleMap(
                      markers: {
                        Marker(
                        markerId: MarkerId('My Location'),
                        position: mapProvider.orderLocation.target,
                        icon: BitmapDescriptor.defaultMarker,
                        ),
                        Marker(
                          markerId: MarkerId('Order Location'),
                          position: mapProvider.myLocation.target,
                          icon: BitmapDescriptor.defaultMarker,
                        ),
                        Marker(
                          markerId: MarkerId('current Marker'),
                          position: mapProvider.currentLocaiton.target,
                          icon: BitmapDescriptor.defaultMarker,
                        )
                        },
                      polylines: {
                        Polyline(
                          // patterns: [
                          //     PatternItem.
                          //   ],
                            visible: true,
                            jointType: JointType.round,
                            geodesic: true,
                            endCap: Cap.roundCap,
                            startCap: Cap.roundCap,
                            polylineId: PolylineId("route"),
                            points: mapProvider.polyLineCoordinates,
                            color: Colors.blue
                        )
                      },
                      cameraTargetBounds: mapProvider.bounds!,
                      mapType: MapType.normal,
                      initialCameraPosition: mapProvider.orderLocation,
                      minMaxZoomPreference: MinMaxZoomPreference(10, 16),
                      onMapCreated: mapProvider.getCurrentLocation,
)

info:

Flutter version 3.0.1

google_maps_flutter: ^2.2.0

dio: ^4.0.6

google_polyline_algorithm: ^3.1.0

0 Answers
Related