PHP code example of geocodefarm / geocodefarm-php

1. Go to this page and download the library: Download geocodefarm/geocodefarm-php 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/ */

    

geocodefarm / geocodefarm-php example snippets




eocodeFarm\GeocodeClient;

// Initialize the client with your API key
$client = new GeocodeClient('YOUR_API_KEY');

// Forward geocoding: address to lat/lon
$response = $client->forward('30 N Gould St, Sheridan, WY');
print_r($response);

// Reverse geocoding: lat/lon to address
$response = $client->reverse(44.797773, -106.954918);
print_r($response);

[
    'success' => true,
    'status_code' => 200,
    'lat' => 44.797773,
    'lon' => -106.954918,
    'accuracy' => 'EXACT_MATCH',
    'full_address' => '30 N Gould St, Sheridan, WY 82801',
    'result' => [
        'house_number' => '30',
        'street_name' => 'N Gould St',
        'locality' => 'Sheridan',
        'admin_2' => 'Sheridan County',
        'admin_1' => 'WY',
        'country' => 'United States',
        'postal_code' => '82801',
        'formatted_address' => '30 N Gould St, Sheridan, WY 82801',
        'latitude' => 44.797773,
        'longitude' => -106.954918,
        'accuracy' => 'EXACT_MATCH'
    ]
]

[
    'success' => false,
    'status_code' => 403,
    'error' => 'API returned failure: INVALID_KEY'
]
bash
composer