Giter Site home page Giter Site logo

dammyololade / flutter_polyline_points Goto Github PK

View Code? Open in Web Editor NEW
103.0 4.0 128.0 389 KB

A flutter plugin that's decodes encoded google poly line string into list of geo-coordinates suitable for showing route/polyline on maps

License: MIT License

Ruby 4.11% Swift 2.54% Objective-C 0.05% Dart 27.38% Kotlin 0.18% CMake 27.51% C++ 33.43% C 2.09% HTML 2.70%

flutter_polyline_points's Introduction

flutter_polyline_points

A flutter plugin that decodes encoded google polyline string into list of geo-coordinates suitable for showing route/polyline on maps

Getting Started

This package contains functions to decode google encoded polyline string which returns a list of co-ordinates indicating route between two geographical position

Usage

To use this package, add flutter_polyline_points as a dependency in your pubspec.yaml file.

Import the package

import 'package:flutter_polyline_points/flutter_polyline_points.dart';

First method

Get the list of points by Geo-coordinate, this return an instance of PolylineResult, which contains the status of the api, the errorMessage, and the list of decoded points.

PolylinePoints polylinePoints = PolylinePoints();
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
        googleApiKey: googleAPiKey,
        request: PolylineRequest(
        origin: PointLatLng(_originLatitude, _originLongitude),
        destination: PointLatLng(_destLatitude, _destLongitude),
        mode: TravelMode.driving,
        wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")],
        ),
);
print(result.points);

Second method

Decode an encoded google polyline string e.g _piFps|U_ulLnnqC_mqNvxq`@

List<PointLatLng> result = polylinePoints.decodePolyline("_p~iF~ps|U_ulLnnqC_mqNvxq`@");
print(result);

Third method

Fetch polyline with alternative routes. This method returns a list of PolylineResult

List<PolylineResult> resulte = await PolylinePoints().getRouteBetweenCoordinates(
      googleApiKey: googleAPiKey,
      request: PolylineRequest(
        origin: PointLatLng(_originLatitude, _originLongitude),
        destination: PointLatLng(_destLatitude, _destLongitude),
        mode: TravelMode.driving,
        wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")],
      ),
    );
print(results.length);

See the example directory for a complete sample app

Hint

kindly ensure you use a valid google api key,
If you need help generating api key for your project click this link

flutter_polyline_points's People

Contributors

a-k-o-r-e-d-e avatar bhavin-concetto avatar charlesarchibong avatar dammyololade avatar enzoseason avatar fadimanakilci avatar hadi20sa avatar maheshj01 avatar nnadir35 avatar tuxbook avatar twklessor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_polyline_points's Issues

Polyline

a polyline is not working, show the only location. Please guide me.

Waypoint LatLng pass

In plugin example you show
wayPoints: [
PolylineWayPoint(location: "location")
]);

In your PolylineWayPoints file your comment
/// as a LatLng, as a google.maps.Place object

I want to pass LatLng to PolyLineWayPoint location. I tried to pass LatLng but it doesn't work. What is the way to pass LatLng there

Feature request: CORS management for web

When I test this package in localhost, it gets cors errors.
Many other packages implemented a cors management via parameter.
Can you implement something like that?

why use http 0.13.0-nullsafety.0?

It's breaking a lot and 0.13.0 is null safe....

Because no versions of flutter_polyline_points match >0.2.6 <0.3.0 and flutter_polyline_points 0.2.6 depends on http ^0.13.0-nullsafety.0, flutter_polyline_points ^0.2.6 requires http ^0.13.0-nullsafety.0.

getRouteBetweenCoordinates() returns an empty list

I tried many times to figure out what was the problem but I did not get any clue, here is my snippet code:

void setPolylines() async {

    PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
      GOOGLE_API_KEY,
      PointLatLng(SOURCE_LOCATION.latitude, SOURCE_LOCATION.longitude),
      PointLatLng(DEST_LOCATION.latitude, DEST_LOCATION.longitude),
      travelMode: TravelMode.driving,
    );

    print(result);
    print(result.points);

    if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }

    setState(() {
      Polyline polyline = Polyline(
          polylineId: PolylineId('poly'),
          color: Colors.blue,
          points: polylineCoordinates);

      _polylines.add(polyline);
    });
  }

Doesn't work on the Web

When I try to decode encoded polyline using flutter for Web it returns very strange results, for example:

 [40.7402, 21400.99565, 40.7402, 21400.995870000002, 21515.576640000003, 21400.996180000002, 42990.413060000006, 21400.99648, 42990.413080000006, 21400.99648, 42990.41311000001, 21400.9965, 42990.41314000001, 21400.99654, 42990.413150000015, 21400.9966, 42990.413150000015, 21400.996619999998, 42990.41323000001, 21400.996619999998, 42990.41434000001, 21400.997669999997, 42990.41444000001, 21400.99775, 42990.414500000006, 42875.8342, 42990.41459000001, 42875.83421, 42990.41466000001, 42875.83425, 42990.41468000001, 42875.83426, 42990.41468000001, 42875.83449, 42990.41475000001, 42875.834520000004, 42990.414780000014, 42875.834570000006, 42990.41486000001, 42875.83470000001, 42990.415060000014, 42875.83490000001, 42990.41518000001, 42875.83498000001, 42990.41523000001, 42875.83499000001, 42990.41574000001, 42875.83503000001, 42990.41614000001, 42875.83504000001, 42990.416280000005, 64350.671510000015, 42990.416600000004, 85825.50787000002, 42990.416840000005, 107300.34422000001, 42990.41711, 128775.18049000001, 42990.4172, 150250.01686, 42990.41739, 171724.85313, 42990.41751, 171724.85333, 42990.41791, 171724.85411000001, 42990.41817, 171724.85462000003, 42990.41833, 171724.85491000002, 42990.41855, 171724.85513, 42990.41865, 171724.85521, 64465.255090000006, 171724.8553, 85940.09149, 171724.85545, 107414.92781000001, 171724.85575000002, 107414.92789, 171724.85585000002, 107414.92792, 171724.85591, 107414.92798000001, 171724.85608000003, 107414.92801, 171724.8563, 107414.92866, 171724.85666000002, 107414.92916, 171724.85693, 107414.92929, 171724.85701, 128889.76575, 171724.8571, 150364.60220000002, 171724.85723999998, 171839.43861, 171724.85794999998, 193314.27494, 171724.85953999998, 214789.11132, 171724.86060999997, 236263.9473, 171724.86570999998, 236263.94731, 171724.86581, 236263.94733, 193199.70228, 236263.94771, 214674.53869000002, 236263.94786000001, 236149.37515, 257738.78414, 236149.37588, 279213.62045, 236149.37656, 300688.45664, 236149.37774, 322163.2931, 236149.37781, 322163.29318000004, 236149.37781, 322163.29342000006, 236149.37784, 322163.29451000004, 236149.37796, 322163.29451000004, 236149.37812, 322163.29453, 236149.37823, 322163.2946, 236149.37833, 322163.29473, 236149.37837000002, 322163.29476, 236149.37872, 343638.13123, 236149.3789, 365112.96767, 236149.37907000002, 386587.80409, 236149.37926000002, 408062.64037, 236149.37985000003, 429537.47677999997, 236149.38015000004, 451012.31318999996, 236149.38029000003, 472487.14955999993, 236149.38042000003, 493961.98582999996, 236149.38069000002, 515436.82226999995, 236149.38081000003, 536911.65871, 236149.38101000004, 558386.49512, 236149.38115000003, 579861.33143, 236149.38156000004, 601336.16775, 236149.38200000004, 622811.00418, 236149.38234000004, 622811.00419, 236149.38248000003, 622811.00424, 236149.38262000002, 622811.00427, 236149.38278, 622811.0043, 236149.38313, 622811.00437, 236149.38381, 644285.84059, 236149.38506, 665760.67703, 236149.38516, 687235.51332, 236149.38597, 708710.3496000001, 236149.38685, 708710.3496900001, 236149.38689000002, 708710.3498300001, 236149.38696000003, 708710.3499, 236149.38701000003, 708710.3499500001, 236149.38708000004, 730185.1864, 236149.38712000006, 730185.18645, 236149.38719000007, 730185.18649, 236149.38725000006, 751660.02294, 236149.38730000006, 773134.85941, 236149.38738000006, 773134.85944, 236149.38746000006, 794609.6954600001, 236149.38895000005, 816084.5318600001, 236149.38931000006, 837559.3683200001, 236149.38965000006, 859034.2043900001, 257624.22562000004, 880509.0406700001, 279099.06190000003, 901983.8770600001, 300573.89822000003, 923458.7134400001, 322048.73453, 944933.5498900001, 322048.73455, 966408.3862700001, 322048.73465, 987883.2226300001, 322048.73478, 1009358.0588900001, 322048.73504, 1030832.8953200001, 322048.7351]

Any ideas to fix it?

How to get the travel duration in the result?

It should be available in Google Directions API. We enable enable billing in google console not to just draw the lines.
Please add the duration based on travelMode in the PolylineResult.
Thank you in advance.

No exception when API key is not valid

This is the response when there is no billing enabled.

{
   "error_message" : "You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable Learn more at https://developers.google.com/maps/gmp-get-started",
   "routes" : [],
   "status" : "REQUEST_DENIED"
}

Roundabout is not drawn correctly

I live in a city with a lot of roundabouts, and when trying your package, i've noted that evertytime i'm aproaching a roundabout, it draws the polylines all around the circle even if i'm just passing by (like taking a left turn to skipt the roundabout) and not entering the roundabout.

Routes with waypoints not working

I'm using your package and when I use the getRouteBetweenCoordinates method with waypoints, the result is empty due to the way you set the queryParam in URI is wrong (within network_util.dart):
You set it like 'waypoints' when it should be 'wayPoints', could you change it please? I did it and is working fine, but I guess when I upgrade your package that change will be lost.

I'm trying to display polylines as per Google road map on my flutter app using authorized google key which is working fine in android app. But In flutter app it's showing unauthorised key.

I'm using google_maps_flutter: ^0.5.11+1 and flutter_polyline_points: ^0.1.0 plugin.

When i'm debugging internal libraries i'm getting following errors in response ->
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 2405:204:969c:11f6::24b9:a8a4, with empty referer",
"routes" : [],
"status" : "REQUEST_DENIED"
}

My code is in this file->
Google_Map_Page.txt

wayPoints error

when i try to add waypoints i get an error.

_TypeError (type 'MappedListIterable<PolylineWayPoint, String>' is not a subtype of type 'List<String>')

Can you show me an example of adding coordinates at waypoints. the examples you have given do not work correctly

RangeError (index): Invalid value: Not in range 0..254

We are getting this error while decoding a polyline.

Encoded polyline:
xyrbEohoaUeMhDyA^i@TWk@q@gDq@cD?eCFgI?wBdAANGPAlMEtEGMmB?iCF[AiCAeK?yEI]AY?o@Ay@AiCA_F?}BBO?UAm@?}@CaFKs]GkTAaDEYAuACoCGkBMaCGsAAqAAmA?mH?uG?cPCcGCaBKcBW}BOcAqAuHo@uCg@yBc@uDSeCgA}PaCq]iAgQgBkWsAgS_@oFi@aKE}DE{JCyQEyFA{KGsVKwc@AwN?}HAyDBqFJuPHoXDaOTeKRwFJ

Stacktrace: (from the library call onwards)
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: RangeError (index): Invalid value: Not in range 0..254, inclusive: 255 #0 String.codeUnitAt (dart:core-patch/string_patch.dart:961:55) #1 NetworkUtil.decodeEncodedPolyline (package:flutter_polyline_points/src/network_util.dart:59:21) #2 PolylinePoints.decodePolyline (package:flutter_polyline_points/flutter_polyline_points.dart:30:17)

This polyline does decode when you put it in the Google Polyline decoder:
https://developers.google.com/maps/documentation/utilities/polylineutility

Does this package support alternate polyline?

I'm using this package with Google maps in my Flutter app I can draw a route between A and B points but between A and B can be alternate paths which I need to draw them on the map, if this package support alternative routes please share a guide how to implement that.

this is my code how to add alternate routes

  _addPolyLine() {
    PolylineId id = PolylineId("poly");
    Polyline polyline = Polyline(
        polylineId: id, color: Colors.red, points: polylineCoordinates);
    polylines[id] = polyline;
    setState(() {});
  }

  _getPolyline() async {
    PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
        googleAPiKey,
        PointLatLng(_originLatitude, _originLongitude),
        PointLatLng(_destLatitude, _destLongitude),
        travelMode: TravelMode.driving,
        wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")]);
    if (result.points.isNotEmpty) {
      result.points.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      });
    }
    _addPolyLine();
  }

Thanks.

index error

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Exception: RangeError (index): Invalid value: Valid value range is empty: 0

lat long change error

double _originLatitude = 6.5212402, _originLongitude = 3.3679965;
double _destLatitude = 6.849660, _destLongitude = 3.648190;
when i try to change this line as is not working
double _originLatitude = 27.6765179, _originLongitude = 85.3471198;
double _destLatitude = 27.7097955, _destLongitude = 85.3264372;

The polyline is not displayed on the map

Hello! I have a problem!
The polyline is not displayed on the map. How to fix?
Now polyline is displayed when i write coordinates by hands, but i think its must be automatically.

DEBUG CONDOLE last message: W/System (31776): A resource failed to call release.

Can not see polly line

Hi
I can not see polly line even after change the coordinate i can see the error in log.

Syncing files to device Redmi Note 6 Pro...
Restarted application in 1,559ms.
I/Google Maps Android API(29203): Google Play services package version: 203315028
E/flutter (29203): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'MappedListIterable<PolylineWayPoint, String>' is not a subtype of type 'List'
E/flutter (29203): #0 NetworkUtil.getRouteBetweenCoordinates (package:flutter_polyline_points/src/network_util.dart:37:20)
E/flutter (29203): #1 PolylinePoints.getRouteBetweenCoordinates (package:flutter_polyline_points/flutter_polyline_points.dart:31:23)
E/flutter (29203): #2 _MapScreenState._getPolyline (package:flutter_app/app_screens/map_polly_line.dart:88:50)

version solving

firebase_auth ^1.0.0 and flutter_polyline_points ^0.2.3, version solving failed.

Only one Way point is working.

Hi,
I am using this package to show Polyline with multiple Waypoints on Google map. But only the first Waypoint in the array is considered in the polyline, rest all are ignored.

Following is the request for source and destination with 2 waypoints, that I can see in the console -

https://maps.googleapis.com/maps/api/directions/json?origin=26.8186007%2C80.9073366&destination=26.8942524%2C80.9453734&mode=driving&avoidHighways=false&avoidFerries=true&avoidTolls=false&key=GOOGLE_API_KEY&waypoints=%5B%7B%22location%22%3A%22Bara+Imambara%2C+Machchhi+Bhavan%2C+Lucknow%2C+Uttar+Pradesh%2C+India%22%2C%22stopover%22%3Atrue%7D%2C%7B%22location%22%3A%22Naka+Market%2C+Unnamed+Road%2C+Arya+Nagar%2C+Charbagh%2C+Lucknow%2C+Uttar+Pradesh%2C+India%22%2C%22stopover%22%3Atrue%7D%5D

Please let me know what can be the issue?

Thanks in advance,
Anuj Jha

travelMode options

I see in Your ex. a : travelMode: TravelMode.driving but don't get this implementations in this plugin? Is it deleted?

create a route with multi points

Using "getRouteBetweenCoordinates" method, it is possible to create a route with more than 2 points (origin and destination).

For do this in flutter_polyline_points I propose the following changes:
in archive flutter_polyline_points.dart add the a new method getRouteFromCoordinates

/// Get the list of coordinates from two or more geographical positions
///
Future getRouteFromCoordinates(
String googleApiKey,
PointLatLng origin,
PointLatLng destination,
List wayPoints,
{TravelMode travelMode = TravelMode.driving,
bool avoidHighways = false,
bool avoidTolls = false,
bool avoidFerries = true,
bool optimizeWaypoints = false}) async {
return await util.getRouteFromCoordinates(
googleApiKey,
origin,
destination,
travelMode,
wayPoints,
avoidHighways,
avoidTolls,
avoidFerries,
optimizeWaypoints);
}

in archive netwok_util.dart add the a new method getRouteFromCoordinates

Future getRouteFromCoordinates(
String googleApiKey,
PointLatLng origin,
PointLatLng destination,
TravelMode travelMode,
List wayPoints,
bool avoidHighways,
bool avoidTolls,
bool avoidFerries,
bool optimizeWaypoints) async {
String mode = travelMode.toString().replaceAll('TravelMode.', '');
PolylineResult result = PolylineResult();
var params = {
"origin": "${origin.latitude},${origin.longitude}",
"destination": "${destination.latitude},${destination.longitude}",
"mode": mode,
"avoidHighways": "$avoidHighways",
"avoidFerries": "$avoidFerries",
"avoidTolls": "$avoidTolls",
"key": googleApiKey
};
if (wayPoints.isNotEmpty) {
List wayPointsArray = List();
wayPoints.forEach((element) {
wayPointsArray.add(element.location);
});
String wayPointsString = wayPointsArray.join('|');
if (optimizeWaypoints) {
wayPointsString = 'optimize:true|$wayPointsString';
}
params.addAll({"waypoints": wayPointsString});
}
Uri uri =
Uri.https("maps.googleapis.com", "maps/api/directions/json", params);

String url = uri.toString();
print('GOOGLE MAPS URL: ' + url);
var response = await http.get(url);
if (response?.statusCode == 200) {
  var parsedJson = json.decode(response.body);
  result.status = parsedJson["status"];
  if (parsedJson["status"]?.toLowerCase() == STATUS_OK &&
      parsedJson["routes"] != null &&
      parsedJson["routes"].isNotEmpty) {
    result.points = decodeEncodedPolyline(
        parsedJson["routes"][0]["overview_polyline"]["points"]);
  } else {
    result.errorMessage = parsedJson["error_message"];
  }
}
return result;

}

If i have permition, i create a new feature branch and commit this for you analyze.

Cannot apply patterns, startCap or endCap on iOS

I have had issues with this package on iOS since I started using it some months ago.
More specifically the issue is that applying pattern or cap styles does not change anything on iOS, while on Android it works as expected. Thus on Android I see this dotted black line with a defined gap, while on iOS I just see a black line. Here's the code segment for the patterns parameter:

int buffer = 0;
final scale = MediaQuery.of(context).devicePixelRatio;
final gap = PatternItem.gap(scale * 6);
Polyline(...,
patterns: polylineCoordinates
   .map((pl) => buffer++ % 2 == 0 ? PatternItem.dot : gap)
   .toList(), ...);

I am quite amazed that no one has addressed this issue here already, as I find it hard to believe I am the only one that experiences it.

Here's the report from flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G2021, locale en-NO)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 4.0)
[✓] Connected device (1 available)

• No issues found!

The designer is now saying that he thinks it looks so bad without the pattern style, that he'd rather just not have it in the app :(
Help is very much appreciated!

Weird decoding of polyline

Hi I am using your library for converting a polyline. I am using the polyline.decode function as explained in your example. I am not sure whether I am doing it wrong somewhere or there is an error in decode logic because the line shows up on my app with weird shapes but when I enter the same encoded string in google's tool I see the correct points being shown.
Here is my code for your reference. I am just converting encoded string to polylines and passing it as a set of polylines to GoogleMaps widget. Thanks!

Given polylines for route is not "snapped" to roads

I am using the flutter_polyline_points package to draw a route between multiple points on my GoogleMap widget (providing start point, end point, and multiple points in between).

The polylines are being drawn perfectly fine, and everything seems to work, except for the fact that the polylines are not "snapped" to the roads, and seem like just a line between each point. Please see this example:

Exmaple image

I am getting the points for the polyline like this:

PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
      kGooglePlacesAPIKey,
      PointLatLng(
        startPoint.latitude,
        startPoint.longitude,
      ),
      PointLatLng(
        endPoint.latitude,
        endPoint.longitude,
      ),
      wayPoints: myAddresses.map((currAddress) {
        return PolylineWayPoint(
          location: '${currAddress.latitude},${currAddress.longitude}',
        );
      }).toList(),
    );

Does anyone know why it is occurring? Is there a way to solve it using this package?

Thank you

Polyline not drawing on map

Hi..I have an issue here. everything is working fine except polyline is not drawing the street line between destination and origin. any update on this?

Thanks for your time
cheers

change avoid parameters Highways | Tolls | Ferries

need to change
- avoidHighways : True
- avoidFerries : True
- avoidTolls : True

CodeBase:
network_util.dart file
line number: 31,32,32

to

  • avoid : highways|ferries|tolls
    please follow below documentations
1. [](https://developers.google.com/maps/documentation/directions/)
2. https://stackoverflow.com/questions/8867122/how-to-avoid-both-tolls-and-highways-for-restrictions-in-google-directions-api

decodePolyline fails for some encoded polylines

decodePolyline works with this argument:

"clgiJchkmBi@QKgCF}@kBCPcG}B]L_IN[G{AD{@l@kAE}@NiA{@`Cq@~@iBpBKjL}Bx@PzBkCrLcBiDn@_BoBoD_CoEcAvAoCcLZc@[cBrAiBu@p@[{Ar@}AqAuGf@u@rDkBe@v@d@xCzCuEvA_CtBcDbD_Hh@jAgA|HyAtEsBtIgBrQ_DmEcAmDsC}K{CaYwAlAVpA"

but fails with this argument:

"_lgiJ_hkmBs@eEiB_@NsF`CR?qAeAUdALR{LyF|Bz@kJ_AnCkDnDi@lLoA\T~BqCbMwAeEb@qAoFaK}@bBgDiOlBoCs@~@a@kB|A{B`C`J|CjElCaUvFmWgAwAwIfQ{CjFe@iCb@{@}EtBkAuN{Aj@i@oDJD"

Both made with the Interactive Polyline Encoder Utility

The second case results in these error messages:

E/flutter (22218): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: RangeError (index): Invalid value: Not in inclusive range 0..154: 155
E/flutter (22218): #0      String.codeUnitAt (dart:core-patch/string_patch.dart:962:55)
E/flutter (22218): #1      NetworkUtil.decodeEncodedPolyline (package:flutter_polyline_points/src/network_util.dart:87:21)
E/flutter (22218): #2      PolylinePoints.decodePolyline (package:flutter_polyline_points/flutter_polyline_points.dart:47:17)
E/flutter (22218): #3      _MyHomePageState.initMap (package:ndskonst/main.dart:162:29)

How can add lat long in waypoint.

I want add the lat long in way point, So I have implement like below:
wayPoints: [PolylineWayPoint(location: "23.3822748%2C74.0206771,23.2537885%2C74.1480252")],
but its' not working.
So please help me for this.
Thank you in Advance.

Polylines not showing

I have tried your sample, markers are visible but the path is not visible.
api key is correct. I can see requests coming from google cloud. directions api is active. please help me

lines are not showing with example code

`import 'package:flutter/material.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class MapScreen extends StatefulWidget {
@OverRide
_MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State {
GoogleMapController mapController;
double _originLatitude = 6.5212402, _originLongitude = 3.3679965;
double _destLatitude = 6.849660, _destLongitude = 3.648190;
Map<MarkerId, Marker> markers = {};
Map<PolylineId, Polyline> polylines = {};
List polylineCoordinates = [];
PolylinePoints polylinePoints = PolylinePoints();

@OverRide
void initState() {
super.initState();

/// origin marker
_addMarker(LatLng(_originLatitude, _originLongitude), "origin",
    BitmapDescriptor.defaultMarker);

/// destination marker
_addMarker(LatLng(_destLatitude, _destLongitude), "destination",
    BitmapDescriptor.defaultMarkerWithHue(90));
_getPolyline();

}

@OverRide
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(_originLatitude, _originLongitude), zoom: 15),
myLocationEnabled: true,
tiltGesturesEnabled: true,
compassEnabled: true,
scrollGesturesEnabled: true,
zoomGesturesEnabled: true,
onMapCreated: _onMapCreated,
markers: Set.of(markers.values),
polylines: Set.of(polylines.values),
)),
);
}

void _onMapCreated(GoogleMapController controller) async {
mapController = controller;
}

_addMarker(LatLng position, String id, BitmapDescriptor descriptor) {
MarkerId markerId = MarkerId(id);
Marker marker =
Marker(markerId: markerId, icon: descriptor, position: position);
markers[markerId] = marker;
}

_addPolyLine() {
PolylineId id = PolylineId("poly");
Polyline polyline = Polyline(
polylineId: id, color: Colors.red, points: polylineCoordinates);
polylines[id] = polyline;
setState(() {});
}

_getPolyline() async {
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
googleAPiKey,
PointLatLng(_originLatitude, _originLongitude),
PointLatLng(_destLatitude, _destLongitude),
// travelMode: TravelMode.driving,
// wayPoints: [PolylineWayPoint(location: "Sabo, Yaba Lagos Nigeria")]
);
//polylineCoordinates.clear();
if (result.points.isNotEmpty) {
result.points.forEach((PointLatLng point) {
polylineCoordinates.add(LatLng(point.latitude, point.longitude));
});
}
_addPolyLine();
}
}`

I am using the example of the code the markers are showing but the route/lines are not showing

[Feature Request] Include Directions API Map Boundary

See this stack overflow link for reference: https://stackoverflow.com/a/66667385

Each Directions API response should include the provided map boundary by default. Including this in the PolylineResult object would provide an extremely useful access point and save some minor but unnecessary additional processing on the client device.

Additional suggestion, since this library is built specifically to use the GCP Directions API, it would also be great if it used the LatLng object provided here: 'package:google_maps_flutter_platform_interface/src/types/location.dart' by default - instead of a custom implementation. It would reduce boilerplate mapping coordinates between the polyline request and the map itself.

This seems like a simple request from my research, and if I had more time I would submit a PR with the changes. If you agree with this feature request (or both) could you do your best to provide a timeline for release so that I can plan development accordingly.

Thanks for your time, and also for providing this package. :)

Directions API issue

I have a map where by it shows the rider and drivers location and I use this package to show the poly lines between them. I call my own custom apis after every 3 seconds to update the rider and driver locations and this way it updates the polyline and increases or decreases the polyline accordingly. is there a cheaper way to use the directions API because After every 3 seconds, a direction API is requested which is costing me. Is there a way I can show the polyline between these two locations without calling the directions api all the time to update the polyline?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.