PHP code example of bodunde / geocoder

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

    

bodunde / geocoder example snippets



namespace Your\Namespace;

use Bodunde\GoogleGeocoder\Geocoder;
...
...
// using dependency injection
public function index(Geocoder $geocoder)
{
  // get coordinates
  $coordinates = $geocoder->getCoordinates('55 Moleye Street, Yaba');

  // get address via reverse geocoding
  $addressCoordinates = [
    "lat" => 6.5349646,
    "lng" => 3.3892894
  ];
  $address = $geocoder->getAddress($addressCoordinates);

  // get distance between two locations
  $location1 = [
    "lat" => 6.5349646,
    "lng" => 3.3892894
  ];

  $location2 = [
    "lat" => 6.601838,
    "lng" => 3.3514863
  ];
  $distance = $geocoder->getDistanceBetween($location1, $location2);

  /** geocoder can also be instantiated normally without DI */
  //e.g $geocoder = new Geocoder;
}