# geocode_class > > **NOTE: There is a file missing (class/key.php)** > > You will need to get your own Google API Key > > Change the **YOUR KEY HERE** with your key. > > Keep the key= part as it is required for the string. > > key.php ``` *** Place this file in the same directory as the class file (geocode.php) ----- Currently this class has three functions. Two require a Google API Key to work. **1) straight_line_distance($lat1, $lon1, $lat2, $lon2, $unit='')**
This will calculate the distance between two sets of Latitudes and Longitudes. using a straight line or as the crow flies.
Using **$unit** you can have it display the distance in (Blank=Miles, K=Kilometers, N=Nautical Miles). Default=Blank or Miles.
Output: Distance Value #### Google API Required Functions. #### **2) getLatLong($address)**
This will return a Latitude and Longitude for a given address in a array format. Output:
$Arr['status'] - Returns Google status for call. Normal = 'OK'
$Arr['lat'] - Returns the Latitude.
$Arr['lon'] - Returns the Longitude.
**3) getDistance($origin, $destination, $mode='driving', $unit='imperial')**
This returns the distance and duration it will take from the Origin to the Destination addresses.
Using **$mode** you can select from three types (driving, walking, bicycling). Default = driving.
Using **$unit** you can select from (imperial = miles or metric = kilometers). Default = imperial.
Output:
$Arr['status'] - Returns Google status for call. Normal = 'OK'
$Arr['distance'] - Returns the distance between origin and the destination.
$Arr['duration'] - Returns how long it will take to get from the origin to the destination.
**geocode-example.php** ```
'; echo $geocode->straight_line_distance(39.10968, -94.57949, 39.17521, -94.53957) ; echo '

' . str_repeat('=',60) . '
'; // -- Get the Lat/Lon of a address ------------------------------------------------------------------------------------- $address = '1600 Pennsylvania Ave NW, Washington, DC 20500

'; echo 'Lat/Lon of address: ' . $address; $latlong = $geocode->getLatLong($address); echo 'STATUS: ' . $latlong['status'] . '
'; echo 'LAT: ' . $latlong['lat'] . '
'; echo 'LON: ' . $latlong['lon'] . '
'; echo '
' . str_repeat('=',60) . '
'; // -- Drive Distance --------------------------------------------------------------------------------------------------- $origin = '1600 Pennsylvania Ave NW, Washington, DC 20500
'; $destination = '1313 Mockingbird Lane, North Hollywood, CA 91602
'; echo 'Drive Distance:
'; echo 'From: ' . $origin . ' to: ' . $destination . '
'; $dist = $geocode->getDistance($origin, $destination, 'driving', 'imperial'); echo 'STATUS: ' . $dist['status'] . '
'; echo 'DISTANCE: ' . $dist['distance'] . '
'; echo 'DURATION: ' . $dist['duration'] . '
'; echo '
' . str_repeat('=',60) . '
'; // == END SCRIPT ======================================================================================================= ```