Update 'README.md'
Cleaned up, finished readme file.
This commit is contained in:
82
README.md
82
README.md
@@ -1,16 +1,86 @@
|
|||||||
# geocode_class
|
# 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
|
||||||
|
```
|
||||||
|
<?php
|
||||||
|
CONST API_KEY = 'key=YOUR KEY HERE';
|
||||||
|
|
||||||
**NOTE: There is a file missing (class/key.php)**
|
```
|
||||||
|
> *** Place this file in the same directory as the class file (geocode.php)
|
||||||
|
|
||||||
You will need to get your own Google API Key
|
-----
|
||||||
|
|
||||||
Change the **YOUR KEY HERE** with your key.
|
Currently this class has three functions. Two require a Google API Key to work.
|
||||||
|
|
||||||
Keep the key= part as it is required for the string.
|
**1) straight_line_distance($lat1, $lon1, $lat2, $lon2, $unit='')** <br/>
|
||||||
|
This will calculate the distance between two sets of Latitudes and Longitudes. using a straight line or as the crow flies.<br/>
|
||||||
|
Using **$unit** you can have it display the distance in (Blank=Miles, K=Kilometers, N=Nautical Miles). Default=Blank or Miles. <br/>
|
||||||
|
|
||||||
key.php
|
Output: Distance Value
|
||||||
|
|
||||||
|
#### Google API Required Functions. ####
|
||||||
|
|
||||||
|
**2) getLatLong($address)** <br/>
|
||||||
|
This will return a Latitude and Longitude for a given address in a array format.
|
||||||
|
|
||||||
|
Output:</br>
|
||||||
|
$Arr['status'] - Returns Google status for call. Normal = 'OK' </br>
|
||||||
|
$Arr['lat'] - Returns the Latitude. <br/>
|
||||||
|
$Arr['lon'] - Returns the Longitude. <br/>
|
||||||
|
|
||||||
|
|
||||||
|
**3) getDistance($origin, $destination, $mode='driving', $unit='imperial')** <br/>
|
||||||
|
This returns the distance and duration it will take from the Origin to the Destination addresses. <br/>
|
||||||
|
Using **$mode** you can select from three types (driving, walking, bicycling). Default = driving. <br/>
|
||||||
|
Using **$unit** you can select from (imperial = miles or metric = kilometers). Default = imperial. <br/>
|
||||||
|
|
||||||
|
Output:</br>
|
||||||
|
$Arr['status'] - Returns Google status for call. Normal = 'OK' </br>
|
||||||
|
$Arr['distance'] - Returns the distance between origin and the destination. <br/>
|
||||||
|
$Arr['duration'] - Returns how long it will take to get from the origin to the destination. <br/>
|
||||||
|
|
||||||
|
|
||||||
|
**geocode-example.php**
|
||||||
```
|
```
|
||||||
<?php
|
<?php
|
||||||
CONST API_KEY = 'key=YOUR KEY HERE';
|
// == GEOCODE CLASS ====================================================================================================
|
||||||
|
require_once 'class/geocode.php';
|
||||||
|
// -- Init Class
|
||||||
|
$geocode = new geocode();
|
||||||
|
|
||||||
|
// -- Straight Line Distance -------------------------------------------------------------------------------------------
|
||||||
|
echo 'Straight Line Distance between two Lat/Lon <br/><br/>';
|
||||||
|
echo $geocode->straight_line_distance(39.10968, -94.57949, 39.17521, -94.53957) ;
|
||||||
|
echo '<br/><br/>' . str_repeat('=',60) . '<br/>';
|
||||||
|
|
||||||
|
// -- Get the Lat/Lon of a address -------------------------------------------------------------------------------------
|
||||||
|
$address = '1600 Pennsylvania Ave NW, Washington, DC 20500 <br/><br/>';
|
||||||
|
echo 'Lat/Lon of address: ' . $address;
|
||||||
|
$latlong = $geocode->getLatLong($address);
|
||||||
|
echo 'STATUS: ' . $latlong['status'] . '<br />';
|
||||||
|
echo 'LAT: ' . $latlong['lat'] . '<br />';
|
||||||
|
echo 'LON: ' . $latlong['lon'] . '<br />';
|
||||||
|
echo '<br/>' . str_repeat('=',60) . '<br/>';
|
||||||
|
|
||||||
|
// -- Drive Distance ---------------------------------------------------------------------------------------------------
|
||||||
|
$origin = '1600 Pennsylvania Ave NW, Washington, DC 20500 <br/>';
|
||||||
|
$destination = '1313 Mockingbird Lane, North Hollywood, CA 91602 <br/>';
|
||||||
|
echo 'Drive Distance: <br/>';
|
||||||
|
echo 'From: ' . $origin . ' to: ' . $destination . '<br/>';
|
||||||
|
$dist = $geocode->getDistance($origin, $destination, 'driving', 'imperial');
|
||||||
|
echo 'STATUS: ' . $dist['status'] . '<br/>';
|
||||||
|
echo 'DISTANCE: ' . $dist['distance'] . '<br/>';
|
||||||
|
echo 'DURATION: ' . $dist['duration'] . '<br/>';
|
||||||
|
echo '<br/>' . str_repeat('=',60) . '<br/>';
|
||||||
|
|
||||||
|
// == END SCRIPT =======================================================================================================
|
||||||
|
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user