PHP code example of alexpechkarev / google-geocoder

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

    

alexpechkarev / google-geocoder example snippets


'providers' => array(
	...
    'Alexpechkarev\GoogleGeocoder\GoogleGeocoderServiceProvider',
)



return [

    /*
    |--------------------------------------------------------------------------
    | Google Geocoder
    |--------------------------------------------------------------------------
    | Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA")
    | into geographic coordinates (like latitude 37.423021 and longitude -122.083739),
    | which you can use to place markers or position the map.
    |
    */

    /*
    |--------------------------------------------------------------------------
    | Application Key
    |--------------------------------------------------------------------------
    |
    | Your application's API key. This key identifies your application for
    | purposes of quota management. Learn how to get a key from the APIs Console.
    */
    'applicationKey' => 'my-api-key',

    /*
    |--------------------------------------------------------------------------
    | Request URL
    |--------------------------------------------------------------------------
    |
    */
    'requestUrl' => [
        'json' => 'https://maps.googleapis.com/maps/api/geocode/json?',
        'xml'  => 'https://maps.googleapis.com/maps/api/geocode/xml?'
    ],
];

return [
    'settings' => [
      /* slim settings */
      'displayErrorDetails' => true,

      'determineRouteBeforeAppMiddleware' => true,

        'google' => [
          'geocoder' => [
            'applicationKey' => 'my-api-key',
            'requestUrl' => [
                'json' => 'https://maps.googleapis.com/maps/api/geocode/json?',
                'xml'  => 'https://maps.googleapis.com/maps/api/geocode/xml?'
            ]
          ]
        ]
    ]
];

use GoogleGeocoder\GoogleGeocoder;

$container['GeoCoder'] = function ($container) {

  return new GoogleGeocoder($container->get('settings')['google']['geocoder']);

};


$gc = $this->container['GeoCoder'];

'applicationKey' => 'your-api-key',

$param = array("address"=>"76 Buckingham Palace Road London SW1W 9TQ");

$response = \Geocoder::geocode('json', $param);

$param = array(
                "address"=>"76 Buckingham Palace Road London SW1W 9TQ",
                "components"=>"country:GB"
            );

$param = array("latlng"=>"40.714224,-73.961452");
$response = \Geocoder::geocode('json', $param);