distance function

Future<DistanceValue> distance(
  1. double lat1,
  2. double lng1,
  3. double lat2,
  4. double lng2, {
  5. String? googleAPIKey,
})

Get the shortest distance according to Google Maps between this two points.

@throw DirectionsException.

Example:

import "package:google_maps_directions/google_maps_directions.dart" as gmd;

int distanceMeters = await gmd.distanceInMeters(9.2460524, 1.2144565, 6.1271617, 1.2345417);
print(distance.meters);//373240
print(distance.text);//"373 km"

{@end-tool}

Implementation

Future<DistanceValue> distance(
  double lat1,
  double lng1,
  double lat2,
  double lng2, {
  String? googleAPIKey,
}) async {
  return (await shortestLeg(
    lat1,
    lng1,
    lat2,
    lng2,
    googleAPIKey: googleAPIKey,
  ))
      .distance;
}