Calculating the Distance Between Two Points
Weather-permitting, most days I take a lunchtime stroll each day from my office, located in close proximity to the corner of Grandview Avenue and 3rd avenue, and denoted by the blue marker found in Figure 1. I walk down to the corner of Grandview Avenue and 5th Avenue, and then double back to the office. How can the distance between these two corners be determine programmatically?
Figure 1. Determining the distance between two points
For starters, a way to plot the two points on the map is needed. To do so, the Google Maps API can be used to add a listener, which will constantly poll the status of the rendered map, waiting for a particular event to occur, such as a mouse click. Clicking the mouse on top of the map will cause the listener to execute another JavaScript method. This listener can be embedded within the load() function, which automatically executes thanks to the onload() event handler attached to the page's tag. The load() JavaScript function and two variables that will be used throughout the script looks like this:
...

Post a Comment