google_routes_flutter 1.0.0 copy "google_routes_flutter: ^1.0.0" to clipboard
google_routes_flutter: ^1.0.0 copied to clipboard

A dart interface for the Google Maps Routes API, which can be used to request directions between two or more locations.

example/google_routes_flutter_example.dart

import 'package:google_routes_flutter/google_routes_flutter.dart';

Future<void> main() async {
  try {
    var computeRoutesResult = await computeRoute(
      origin: Waypoint(
        location: Location(
          latLng: LatLng(
            latitude: 33.25889341635255,
            longitude: 35.210018284644185,
          ),
        ),
      ),
      destination: Waypoint(
        location: Location(
          latLng: LatLng(
            latitude: 33.278430320176085,
            longitude: 35.216819613960894,
          ),
        ),
      ),
      xGoogFieldMask: 'routes.distanceMeters,routes.routeLabels',
      apiKey: 'YOUR_API_KEY',
    );

    var computeRouteMatrixResult = await computeRouteMatrix(
      origins: [
        RouteMatrixOrigin(
          waypoint: Waypoint(
            location: Location(
              latLng: LatLng(
                latitude: 33.25889341635255,
                longitude: 35.210018284644185,
              ),
            ),
          ),
        ),
      ],
      destinations: [
        RouteMatrixDestination(
          waypoint: Waypoint(
            location: Location(
              latLng: LatLng(
                latitude: 33.278430320176085,
                longitude: 35.216819613960894,
              ),
            ),
          ),
        ),
      ],
      xGoogFieldMask: 'distanceMeters',
      apiKey: 'YOUR_API_KEY',
    );

    print(
      'API Call 1: distance is '
      '${computeRoutesResult.routes?.firstWhere(
            (route) =>
                (route.routeLabels?.contains(RouteLabel.defaultRoute) ?? false),
          ).distanceMeters}'
      ' meters',
    );

    print(
      'API Call 2: distance is '
      '${computeRouteMatrixResult.first.distanceMeters}'
      ' meters',
    );
  } catch (e) {
    print(e);
  }
}
7
likes
150
pub points
66%
popularity

Publisher

unverified uploader

A dart interface for the Google Maps Routes API, which can be used to request directions between two or more locations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

http, json_annotation

More

Packages that depend on google_routes_flutter