6. Find the Distance Between Two Points

Playback Speed:
Transcript

In this video, you will find the distance between two locations in your spreadsheet.

Google Maps sometimes calculates several routes between two locations.

Tell the application to use the first option it calculates.

Type “dot routes” after “directions.”

Then, in square brackets, type “Zero.”

Each route is made of several legs, or segments of the journey.

Type “dot legs” with a zero in brackets.

Finally, to fetch the distance between the two points, type “dot distance.”

Then, type “dot value” to retrieve the numerical value of the distance.

Take a look at your code.

It reads: “Get the distance of the first and only leg of the journey along a route between the two points.”

Wow!

Next, run the program and check the log.

The program returns the distance value in meters, not miles.

Now that you have checked the code in the log and know that it works, store the distance in meters in another variable.

To define a “meters” variable, type “V-A-R meters equals.”

Copy or retype the directions code you just logged.

Then, define a “miles” variable that contains a mathematical operation that will convert meters to miles.

Perform a quick internet search to find out how many meters are in one mile.

Or, if you prefer kilometers, divide the number of meters by 1 thousand.

Type the calculation into your code.

The log records the two addresses, the distance between them in meters, and the distance in miles.

Great!

Compare the distances.

The values are the same.

Fantastic!

Now, it’s your turn: Specify which directions to use from the Google Maps API.

Specify the number of legs in your directions.

Fetch the distance property.

Then, define a meters variable.

Finally, convert meters to miles.

Then, move on to the next video.

Instructions
1. Specify which directions to use from the Google Maps API.
2. Specify the number of legs in your directions.
3. Fetch the distance property.
4. Define a meters variable.
5. Define a miles variable with a mathematical operation that converts meters to miles.