2017 © Pedro Peláez
 

library google-maps

Collection of Google Maps API Web Services for Laravel

image

alexpechkarev/google-maps

Collection of Google Maps API Web Services for Laravel

  • Wednesday, January 24, 2018
  • by alexpechkarev
  • Repository
  • 19 Watchers
  • 219 Stars
  • 144,767 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 57 Forks
  • 0 Open issues
  • 10 Versions
  • 16 % Grown

The README.md

Collection of Google Maps API Web Services for Laravel

Provides convenient way of setting up and making requests to Maps API from Laravel application. For services documentation, API key and Usage Limits visit Google Maps API Web Services and Maps API for Terms of Service License Restrictions., (*1)

Features

Dependency

Notes

Rmoving Place Add, Delete & Radar Search features, (*2)

Requests to the Places API attempting to use these features will receive an error response * Place Add * Place Delete * Radar Search, (*3)

Deprication notices for Google Places API Web Service that effects Premium data (Zagat), types parameter, id and reference fields., (*4)

  • Nearby Search - types parameter depricated, use parameter type (string)
  • Place Details - the reference is now deprecated in favor of placeid (placeid originally used in this package)
  • Place Add - still uses types parameter as per service documentation
  • Place Autocomplete - still uses types parameter as per service documentation

Installation

Issue following command in console:, (*5)

composer require alexpechkarev/google-maps

Alternatively edit composer.json by adding following line and run composer update, (*6)

"require": {
        ....,
        "alexpechkarev/google-maps":"^11.0",

    },

Configuration

Register package service provider and facade in 'config/app.php', (*7)

'providers' => [
    ...
    GoogleMaps\ServiceProvider\GoogleMapsServiceProvider::class,
]

'aliases' => [
    ...
    'GoogleMaps' => GoogleMaps\Facade\GoogleMapsFacade::class,
]

Publish configuration file using php artisan vendor:publish --tag=googlemaps or simply copy package configuration file and paste into config/googlemaps.php, (*8)

Open configuration file config/googlemaps.php and add your service key, (*9)

    /*
    |----------------------------------
    | Service Keys
    |------------------------------------
    */

    'key'       => 'ADD YOUR SERVICE KEY HERE',

If you like to use different keys for any of the services, you can overwrite master API Key by specifying it in the service array for selected web service., (*10)

Usage

Here is an example of making request to Geocoding API:, (*11)

$response = \GoogleMaps::load('geocoding')
        ->setParam (['address' =>'santa cruz'])
        ->get();

By default, where appropriate, output parameter set to JSON. Don't forget to decode JSON string into PHP variable. See Processing Response for more details on parsing returning output., (*12)

Required parameters can be specified as an array of key:value pairs:, (*13)

$response = \GoogleMaps::load('geocoding')
        ->setParam ([
            'address'    =>'santa cruz',
                'components' => [
                        'administrative_area'  => 'TX',
                        'country'              => 'US',
                      ]

                ])
                ->get();
 ```

Alternatively parameters can be set using `setParamByKey()` method. For deeply nested array use "dot" notation as per example below.

```php
$endpoint = \GoogleMaps::load('geocoding')
   ->setParamByKey('address', 'santa cruz')
   ->setParamByKey('components.administrative_area', 'TX') //return $this
    ...

Another example showing request to Places API Place Add service:, (*14)

$response = \GoogleMaps::load('placeadd')
                ->setParam([
                   'location' => [
                        'lat'  => -33.8669710,
                        'lng'  => 151.1958750
                      ],
                   'accuracy'           => 0,
                   "name"               =>  "Google Shoes!",
                   "address"            => "48 Pirrama Road, Pyrmont, NSW 2009, Australia",
                   "types"              => ["shoe_store"],
                   "website"            => "http://www.google.com.au/",
                   "language"           => "en-AU",
                   "phone_number"       =>  "(02) 9374 4000"
                          ])
                  ->get();

Available methods


load( $serviceName ) - load web service by name, (*15)

Accepts string as parameter, web service name as specified in configuration file. Returns reference to it's self., (*16)


\GoogleMaps::load('geocoding') ...

setEndpoint( $endpoint ) - set request output, (*17)

Accepts string as parameter, json or xml, if omitted defaulted to json. Returns reference to it's self., (*18)

$response = \GoogleMaps::load('geocoding')
        ->setEndpoint('json')  // return $this
        ...

getEndpoint() - get current request output, (*19)

Returns string., (*20)

$endpoint = \GoogleMaps::load('geocoding')
        ->setEndpoint('json')
        ->getEndpoint();

echo $endpoint; // output 'json'

setParamByKey( $key, $value ) - set request parameter using key:value pair, (*21)

Accepts two parameters: * key - body parameter name * value - body parameter value, (*22)

Deeply nested array can use 'dot' notation to assign value. Returns reference to it's self., (*23)

$endpoint = \GoogleMaps::load('geocoding')
   ->setParamByKey('address', 'santa cruz')
   ->setParamByKey('components.administrative_area', 'TX') //return $this
    ...

setParam( $parameters) - set all request parameters at once, (*24)

Accepts array of parameters Returns reference to it's self., (*25)

$response = \GoogleMaps::load('geocoding')
                ->setParam([
                   'address'     => 'santa cruz',
                   'components'  => [
                        'administrative_area'   => 'TX',
                        'country'               => 'US',
                         ]
                     ]) // return $this
...

* get() - perform web service request (irrespectively to request type POST or GET ) * get( $key ) - accepts string response body key, use 'dot' notation for deeply nested array, (*26)

Returns web service response in the format specified by setEndpoint() method, if omitted defaulted to JSON. Use json_decode() to convert JSON string into PHP variable. See Processing Response for more details on parsing returning output., (*27)

$response = \GoogleMaps::load('geocoding')
                ->setParamByKey('address', 'santa cruz')
                ->setParamByKey('components.administrative_area', 'TX')
                 ->get();

var_dump( json_decode( $response ) );  // output

/*
{\n
   "results" : [\n
      {\n
         "address_components" : [\n
            {\n
               "long_name" : "277",\n
               "short_name" : "277",\n
               "types" : [ "street_number" ]\n
            },\n
            ...
*/


Example with $key parameter, (*28)

$response = \GoogleMaps::load('geocoding')
                ->setParamByKey('latlng', '40.714224,-73.961452')
                 ->get('results.formatted_address');

var_dump( json_decode( $response ) );  // output

/*
array:1 [▼
  "results" => array:9 [▼
    0 => array:1 [▼
      "formatted_address" => "277 Bedford Ave, Brooklyn, NY 11211, USA"
    ]
    1 => array:1 [▼
      "formatted_address" => "Grand St/Bedford Av, Brooklyn, NY 11211, USA"
    ]
            ...
*/



isLocationOnEdge( $lat, $lng, $tolrance = 0.1 ) - To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass the point, the polyline/polygon, and optionally a tolerance value in degrees., (*29)

This method only available with Google Maps Directions API., (*30)

Accepted parameter: * $lat - double latitude * $lng - double longitude * $tolrance - double, (*31)

$response = \GoogleMaps::load('directions')
            ->setParam([
                'origin'          => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE',
                'destination'     => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y',
            ])
           ->isLocationOnEdge(55.86483,-4.25161);

    dd( $response  );  // true

containsLocation( $lat, $lng ) -To find whether a given point falls within a polygon., (*32)

This method only available with Google Maps Directions API., (*33)

Accepted parameter: * $lat - double latitude * $lng - double longitude, (*34)

$response = \GoogleMaps::load('directions')
            ->setParam([
                'origin'          => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE',
                'destination'     => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y',
            ])
           ->containsLocation(55.86483,-4.25161);

    dd( $response  );  // true

Support

Please open an issue on GitHub, (*35)

License

Collection of Google Maps API Web Services for Laravel is released under the MIT License. See the bundled LICENSE file for details., (*36)

The Versions

24/01 2018

dev-master

9999999-dev https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

09/01 2018

1.0.9

1.0.9.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

29/08 2017

1.0.8

1.0.8.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

15/06 2017

dev-add-code-of-conduct-1

dev-add-code-of-conduct-1 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

24/11 2016

1.0.7

1.0.7.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

15/04 2016

1.0.5

1.0.5.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

29/01 2016

1.0.4

1.0.4.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service google maps api for laravel google maps web service for laravel laravel google maps api

11/09 2015

1.0.2

1.0.2.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service

07/09 2015

1.0.1

1.0.1.0 https://alexpechkarev.github.io/google-maps/

Collection of Google Maps API Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service

03/09 2015

1.0

1.0.0.0

Collection of Google Maps Web Services for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Pechkarev

google maps api geocoding api directions api distance matrix api elevation api geolocation api roads api time zone api places api web service