PHP code example of dericcain / geo-things

1. Go to this page and download the library: Download dericcain/geo-things library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dericcain / geo-things example snippets


// You will need to declare the namespace
use GeoThing/GeoThing;

$address = '123 Main Street';
$zip = '32119';

$results = GeoThing::getCoordinates($address, $zip);

$results->lat // 33.5075002
$results->lng // -86.8105789
$results->error // The error code from Google if there is one. This attribute will not be here if there is not error.

// You will need to declare the namespace
use GeoThing/GeoThing;

$response = GeoThing::getAddress($lat, $lng);

$response->error // This will only be set if there is an error
$response->street_number // The number only
$response->street_name // The name of the street
$response->city // The full city name
$response->state // The full state name, not the abbreviation
$response->zip // The zip code
$response->formatted_address // The full formated address "277 Bedford Avenue, Brooklyn, NY 11211, USA"

// You will need to declare the namespace
use GeoThing/GeoThing;

$response = GeoThing::getDistance($origin, $destination);

$response->error // This will only be set if there is an error
$response->distance // This will be a string like "1.2 mi" (I'll change this soon)
$response->duration // This will also be a string as of right now

getAddress($lat, $lng, $apiKey); // $apiKey is optional
getCoordinates($address, $zip, $apiKey); // $apiKey is optional
getDistance($origin, $destination, $apiKey); // $apiKey is optional