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

Overview

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,
        _originLatitude, _originLongitude, _destLatitude, _destLongitude);
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);

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

Comments
  • Polyline not drawing on map

    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

    opened by rizalsafril 19
  • Issue with virtual display size , It says created display size is larger than device screen size.

    Issue with virtual display size , It says created display size is larger than device screen size.

    Below error i am getting...

    Creating a virtual display of size: [1080, 2210] may result in problems(https://github.com/flutter/flutter/issues/2897).It is larger than the device screen size: [1080, 2131]

    opened by prabhunath111 18
  • Waypoint LatLng pass

    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

    opened by ziasultan2 13
  • The polyline is not displayed on the map

    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.

    opened by RenatBack 7
  • wayPoints error

    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

    opened by ismetatakli 6
  • Valid Value range is empty on polylinePoints.getRouteBetweenCoordinates()

    Valid Value range is empty on polylinePoints.getRouteBetweenCoordinates()

    I get this error on call of polylinePoints.getRouteBetweenCoordinates()

    Exception has occurred.
    _Exception (Exception: RangeError (index): Invalid value: Valid value range is empty: 0)
    
    opened by tayormi 5
  • create a route with multi points

    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.

    opened by gufrancisco 4
  • why use http 0.13.0-nullsafety.0?

    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.

    opened by smasinde 2
  • 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 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

    opened by bhagyashrieducloud 2
  • lat long change error

    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;

    opened by shree-krishna-gapi 2
  • decodePolyline fails for some encoded polylines

    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)
    
    opened by BoHellgren 2
  • How to get the travel duration in the result?

    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.

    opened by topex-psy 2
  • Received error code [OVER_QUERY_LIMIT] when using function getRouteBetweenCoordinates()

    Received error code [OVER_QUERY_LIMIT] when using function getRouteBetweenCoordinates()

    Yesterday I was able to use it, but today when I called for the 2nd time it returned the error [OVER_QUERY_LIMIT]. I make sure I only call getRouteBetweenCoferences() 1 time at a time. Statistics from my google API. image what should I do to solve this problem?

    opened by anhTuan0712 0
  • Does this package support alternate polyline?

    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.

    opened by ziagit 1
  • No exception when API key is not valid

    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"
    }
    
    opened by shaifuliotait 0
  • Given polylines for route is not

    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]1

    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

    opened by Yahllil 4
Owner
Adeyemo Adedamola
A Software Engineer with great expertise in Android, IOS, NodeJs, Php, Dart(Flutter)
Adeyemo Adedamola
A Flutter example to use Google Maps in iOS and Android apps via the embedded Google Maps plugin Google Maps Plugin

maps_demo A Flutter example to use Google Maps in iOS and Android apps via the embedded Google Maps plugin Google Maps Plugin Getting Started Get an A

Gerry High 41 Feb 14, 2022
A migration of Google Maps Application with Flutter & Google Maps APIs including: Maps SDK for Android & IOS, Places API & polylines

google_maps A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

TAD 1 Mar 4, 2022
Flutter Maps A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Salsabil Mohamed Hemada 1 Jul 15, 2022
A flutter plugin for Google Maps

IMPORTANT: This plugin is no longer under development Why? We initially built this plugin to fill an early gap in flutter. Since then, Google has made

AppTree Software, Inc 415 Dec 29, 2022
A Flutter plugin for integrating Google Maps in iOS, Android and Web applications

flutter_google_maps A Flutter plugin for integrating Google Maps in iOS, Android and Web applications. It is a wrapper of google_maps_flutter for Mobi

MarchDev Toolkit 86 Sep 26, 2022
A Flutter plugin which provides 'Picking Place' using Google Maps widget

Google Maps Places Picker Refractored This is a forked version of google_maps_place_picker package, with added custom styling and features.

Varun 5 Nov 13, 2022
Flutter Google Maps Tutorial

Flutter Google Maps Tutorial YouTube Video Setup Get an API Key at https://cloud.google.com/maps-platform/ Enable Maps SDK for Android, Maps SDK for i

Marcus Ng 85 Nov 30, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Youhaan bootwala 1 Mar 18, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Varun CN 2 Apr 19, 2022
This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with simple smooth animations, making a nice UI and UX.

search_map_place This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with

Lucas Bernardi 127 Oct 22, 2022
Easy Google Maps for Flutter

easy_google_maps Easy Google Maps for Flutter on Web and Mobile Getting Started Mobile Follow setup for Mobile Here Web Good to go! EasyGoogleMaps(

Rody Davis 69 Jul 19, 2022
Place picker on Google Maps for Flutter

Google Maps Place Picker A Flutter plugin which provides 'Picking Place' using Google Maps widget. The project relies on below packages. Map using Flu

Terry Kwon 178 Dec 16, 2022
A car rental flutter application using firebase and google maps API

A car sharing & rental app using Flutter, Firebase & Google Maps APIs ?? About the App ?? hopOn is flutter based application for car sharing and renta

Shivani Singh 97 Dec 30, 2022
Simple flutter app demonstrating usage of Google Maps

flutter_maps_example Get an API key at GoogleCloud. Enable Google Map SDK for ea

Tornike Gogberashvili 0 Nov 23, 2022
Flutter Google Maps My Track

mytracker We invite you to subscribe to the Alpha flutter code channel on Youtub

NELSON YUNGA 6 Oct 31, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Tsenda LAB 1 Mar 28, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Dreamfullstacker 16 Dec 31, 2022
Flutter package to enable clustering of location markers on Google Maps using widgets specific to each location.

flutter_google_maps_widget_cluster_markers This widget implements a very specific adaptation of google_maps_cluster_manager, allowing different ,marke

Kek Tech 2 Jan 6, 2023
Aplications with google maps and geolocation

Aplications with google maps and geolocation

Richardson Tsavo 4 Jul 26, 2022