Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.87 KB | None | 0 0
  1. Future<void> _getDistance(PlacesDetailsResponse start,
  2.       PlacesDetailsResponse end,) async {
  3.     List<Location> origin = [
  4.       start.result.geometry.location,
  5.     ];
  6.     List<Location> destination = [
  7.       end.result.geometry.location,
  8.     ];
  9.  
  10.     GoogleDistanceMatrix distanceMatrix =
  11.     new GoogleDistanceMatrix(apiKey: kGoogleApiKey);
  12.  
  13.     DistanceResponse response = await distanceMatrix.distanceWithLocation(
  14.       origin,
  15.       destination,
  16.     );
  17.  
  18.     try {
  19.       if (response.isOkay) {
  20.         response.results.forEach((row) {
  21.           row.elements.forEach((element) {
  22.             distance = element.distance;
  23.             duration = element.duration;
  24.           });
  25.         });
  26.       } else {
  27.         print('ERROR: ${response.errorMessage}');
  28.         Future.error(Error());
  29.       }
  30.     } finally {
  31.       distanceMatrix.dispose();
  32.     }
  33.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement