daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Mar 13th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top