2017 © Pedro Peláez
 

library geocoder

Geocoding addresses to coordinates

image

axelb/geocoder

Geocoding addresses to coordinates

  • Wednesday, April 25, 2018
  • by axelb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 44 Forks
  • 1 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

Geocode addresses to coordinates

Latest Version Software License Build Status SensioLabsInsight StyleCI Total Downloads, (*1)

This package can convert any address to GPS coordinates using Google's geocoding service. Here's a quick example:, (*2)

Geocoder::getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');

// will return this array
[
   'lat' => 51.2343564,
   'lng' => 4.4286108,,
   'accuracy' => 'ROOFTOP',
   'formatted_address' => 'Samberstraat 69, 2060 Antwerpen, Belgium',
   'viewport' => [
       "northeast" => [
            "lat" => 51.23570538029149,
            "lng" => 4.429959780291502
        ],
        "southwest" => [
            "lat" => 51.2330074197085,
            "lng" => 4.427261819708497
        ]
   ]
]

Installation

You can install this package through composer., (*3)

composer require spatie/geocoder

Laravel installation

Thought the package works fine in non-Laravel projects we included some niceties for our fellow artistans., (*4)

In Laravel 5.5 the package will autoregister itself. In older versions of Laravel your must manually installed the service provider and facade., (*5)

// config/app.php
'providers' => [
    '...',
    Spatie\Geocoder\GeocoderServiceProvider::class
];
// config/app.php
'aliases' => array(
    ...
    'Geocoder' => Spatie\Geocoder\Facades\Geocoder::class,
)

Next, you must publish the config file :, (*6)

php artisan vendor:publish --provider="Spatie\Geocoder\GeocoderServiceProvider" --tag="config"

This is the content of the config file:, (*7)

return [

   /*
    * The api key used when sending Geocoding requests to Google.
    */
   'key' => env('GOOGLE_MAPS_GEOCODING_API_KEY', ''),


   /*
    * The language param used to set response translations for textual data.
    *
    * More info: https://developers.google.com/maps/faq#languagesupport
    */

   'language' => '',

   /*
    * The region param used to finetune the geocoding process.
    *
    * More info: https://developers.google.com/maps/documentation/geocoding/intro#RegionCodes
    */
   'region' => '',

    /*
     * The bounds param used to finetune the geocoding process.
     *
     * More info: https://developers.google.com/maps/documentation/geocoding/intro#Viewports
     */
    'bounds' => '',

];

Usage

Here's how you can use the Geocoder., (*8)

$client = new GuzzleHttp\Client();

$geocoder = new Geocoder($client);

$geocoder->getCoordinatesForAddress('Infinite Loop 1, Cupertino', $apiKey);

/* 
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "formatted_address" => "1 Infinite Loop, Cupertino, CA 95014, USA",
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/

You can get the result back in a specific language., (*9)

$geocoder
   ->getCoordinatesForAddress('Infinite Loop 1, Cupertino')
   ->setLanguage('it');

/* 
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/

This is how you can reverse geocode coordinates to addresses., (*10)

$geocoder->getAddressForCoordinates(40.714224, -73.961452);

/* 
  This function returns an array with keys
  "lat" => 40.7142205
  "lng" => -73.9612903
  "accuracy" => "ROOFTOP"
  "formatted_address" => "277 Bedford Ave, Brooklyn, NY 11211, USA",
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/

If you are using the package with Laravel, you can simply call getCoordinatesForAddress., (*11)

Geocoder::getCoordinatesForAddress('Infinite Loop 1, Cupertino');

/* 
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "formatted_address" => "1 Infinite Loop, Cupertino, CA 95014, Stati Uniti",
    "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/

The accuracy key can contain these values: - ROOFTOP - RANGE_INTERPOLATED - GEOMETRIC_CENTER - APPROXIMATE, (*12)

You can read more information about these values on the Google Geocoding API Page, (*13)

When an address is not found accuracy and formatted_address will contain NOT_FOUND, (*14)

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using., (*15)

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium., (*16)

We publish all received postcards on our company website., (*17)

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*18)

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff., (*19)

License

The MIT License (MIT). Please see License File for more information., (*20)

The Versions

25/04 2018

dev-master

9999999-dev https://github.com/AxelBCreative/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

20/04 2018

3.3.0

3.3.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

30/03 2018

3.2.0

3.2.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

22/02 2018

3.1.1

3.1.1.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

25/10 2017

3.1.0

3.1.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

24/10 2017

3.0.1

3.0.1.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

24/10 2017

3.0.0

3.0.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

15/11 2016

2.3.2

2.3.2.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

04/09 2016

2.3.1

2.3.1.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

01/09 2016

2.3.0

2.3.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

01/09 2016

dev-analysis-XpELpV

dev-analysis-XpELpV https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

20/08 2016

2.2.0

2.2.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

07/08 2016

2.1.3

2.1.3.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

04/07 2016

2.1.2

2.1.2.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

10/03 2016

2.1.1

2.1.1.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

24/07 2015

2.1.0

2.1.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

12/06 2015

2.0.0

2.0.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

23/05 2015

1.0.0

1.0.0.0 https://github.com/spatie/geocoder

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

01/10 2014

0.1.2

0.1.2.0

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode

01/05 2014

0.1.1

0.1.1.0

Geocoding addresses to coordinates

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel map location coordinate geocode