Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting polylines to pass GoogleMap() widget #78

Open
gadishimwe opened this issue Jun 24, 2020 · 2 comments
Open

Getting polylines to pass GoogleMap() widget #78

gadishimwe opened this issue Jun 24, 2020 · 2 comments

Comments

@gadishimwe
Copy link

Hello. I've been searching over the internet including your API references and documentation, but I can't find any resource of full usage of your package. I want to use google_maps_webservice/directions to implement in-app navigation, but I can't find a way to do it. Can you please help me to achieve that? Any help would be much appreciated. Thanks

@cyenite
Copy link

cyenite commented Dec 11, 2022

Hello @gadishimwe,
I also came across this issue and so I created a custom function to decode polyline points from the routes.
The polyline string to decode can be accessed through: route.overviewPolyline.points.
Pass the string to the following function, and it will return a list of coordinates(LatLng):

List<LatLng> decodeEncodedPolyline(String encoded) {
    List<LatLng> poly = [];
    int index = 0, len = encoded.length;
    int lat = 0, lng = 0;

    while (index < len) {
      int b, shift = 0, result = 0;
      do {
        b = encoded.codeUnitAt(index++) - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
      } while (b >= 0x20);
      int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
      lat += dlat;

      shift = 0;
      result = 0;
      do {
        b = encoded.codeUnitAt(index++) - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
      } while (b >= 0x20);
      int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
      lng += dlng;
      LatLng p = new LatLng((lat / 1E5).toDouble(), (lng / 1E5).toDouble());
      poly.add(p);
    }
    return poly;
  }

@gadishimwe
Copy link
Author

Hi @cyenite,

Thank you for your response. Unfortunately, I wasn't looking for a way to draw just the routes. I wanted to implement in-app turn-to-turn navigation and later I found out that it wasn't supported or implemented because Google want us to use their Google Maps app instead.

flutter/flutter#64404
flutter/flutter#29277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants