From d20caa7b5a5ac401117dccbfb7dca4885694173b Mon Sep 17 00:00:00 2001 From: Rick Hays Date: Sat, 28 Sep 2019 14:27:16 -0500 Subject: [PATCH] Update 'README.md' Cleaned up, finished readme file. --- README.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4656ca5..0b7e2b6 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,86 @@ # 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) + +----- -**NOTE: There is a file missing (class/key.php)** +Currently this class has three functions. Two require a Google API Key to work. -You will need to get your own Google API Key +**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.
-Change the **YOUR KEY HERE** with your key. +Output: Distance Value -Keep the key= part as it is required for the string. +#### Google API Required Functions. #### -key.php +**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 ======================================================================================================= + +``` \ No newline at end of file