PHP code example of assghard / php-geocoders

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

    

assghard / php-geocoders example snippets


use Assghard\PhpGeocoders\GeocodingService;
use Assghard\PhpGeocoders\Providers\NominatimGeocoderProvider;

$geocoder = new NominatimGeocoderProvider();
$geocodingService = new GeocodingService($geocoder);

// Get coordinates by address
$geocodeData = $geocodingService->geocode($addressAsString);

// Get address by coordinates
$reverseData = $geocodingService->reverse($latitude, $longitude);


$geocoder = new NominatimGeocoderProvider('en');

$geocoder = new NominatimGeocoderProvider(['en', 'pl']);

use Assghard\PhpGeocoders\GeocodingService;
use Assghard\PhpGeocoders\Providers\GoogleGeocoderProvider;

$geocoder = new GoogleGeocoderProvider('GOOGLE_MAPS_API_KEY', 'en');
/**
 * "en" - English language code. See Google documentation: https://developers.google.com/admin-sdk/directory/v1/languages
 * 
 * Google Maps javascript API documentation: https://developers.google.com/maps/documentation/javascript/overview
 */
$geocodingService = new GeocodingService($geocoder);
$geocodeData = $geocodingService->geocode($addressAsString); // Get coordinates by address
$reverseData = $geocodingService->reverse($latitude, $longitude); // Get address by coordinates