Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Future<void> _getDistance(PlacesDetailsResponse start,
- PlacesDetailsResponse end,) async {
- List<Location> origin = [
- start.result.geometry.location,
- ];
- List<Location> destination = [
- end.result.geometry.location,
- ];
- GoogleDistanceMatrix distanceMatrix =
- new GoogleDistanceMatrix(apiKey: kGoogleApiKey);
- DistanceResponse response = await distanceMatrix.distanceWithLocation(
- origin,
- destination,
- );
- try {
- if (response.isOkay) {
- response.results.forEach((row) {
- row.elements.forEach((element) {
- distance = element.distance;
- duration = element.duration;
- });
- });
- } else {
- print('ERROR: ${response.errorMessage}');
- Future.error(Error());
- }
- } finally {
- distanceMatrix.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement