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.
“Get the distance of the first and only leg of the journey
along a route between the two points.”
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.
Run your program.
The log records the two addresses,
the distance between them in meters,
and the distance in miles.
To verify your results, go to maps.google.com and get directions between the two addresses.
Compare the distances.
The values are the same.
In the next video, you will write code that gets the addresses from your spreadsheet.
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.