This is a fork of https://github.com/SachinAgarwal1337/google-places-api.
I added model classes for results, API to retrieve photos, and caching.
This is a PHP wrapper for Google Places Api Web Service. And is Laravel Framework friendly.
With just 2 lines of code you can request to any google places api feature. No need to manually perform any curl requests.
- Place Search return a list of places based on a user's location or search string.
- Place Details requests return more detailed information about a specific Place, including user reviews.
- Place Autocomplete can be used to automatically fill in the name and/or address of a place as you type.
- Query Autocomplete can be used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
Install it with composer
composer require vovanmix/google-places-api
Laravel user can see the Laravel Usage section
use Vovanmix\GoogleApi\PlacesApi;
$googlePlaces = new PlacesApi('API KEY');
Note: You can also set the API KEY after initaiting the class using setKey('KEY')
method. You can chain this with method with anyother methods.
Example:
$response = $googlePlaces->placeAutocomplete('some Place');
As mentioned earlier just 2 lines of code to make any request.
Full example:
use Vovanmix\GoogleApi\PlacesApi;
function () {
$googlePlaces = new PlacesApi('API_KEY') # line 1
$response = $googlePlaces->placeAutocomplete('some input'); # line 2
}
Set up the service provider and facade in the config\app.php
'providers' => [
....
....
Vovanmix\GoogleApi\ServiceProvider::class,
];
'aliases' => [
....
....
'GooglePlaces' => Vovanmix\GoogleApi\Facade::class,
];
publish the config file with following artisan command
php artisan vendor:publish --provider="Vovanmix\GoogleApi\ServiceProvider"
This will create google.php file in the config directory.
Set the API KEY in this config file.
Start using the package using Facade.
$response = GooglePlaces::placesAutocomplete('some city');
The response returned is a Laravel's Collection so that you can perform any of the available collection methods on it.
If you are not familiar with Laravel's Collecton you can either reference the docs here or you can use response as simple array.
location
— The latitude/longitude around which to retrieve place information. This must be specified as latitude,longitude.- 'radius' — Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50 000 meters. Note that
radius
must not be included ifrankby=distance
(described under Optional parameters below) is specified. - If
rankby=distance
(described under Optional parameters below) is specified, then one or more ofkeyword
,name
, ortypes
is required. params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
query
— The text string on which to search, for example: "restaurant". The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance.params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
location
— The latitude/longitude around which to retrieve place information. This must be specified as latitude,longitude.radius
— Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50 000 meters.params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
Note: A Radar Search request must include at least one of keyword
, name
, or types
.
placeId
— A textual identifier that uniquely identifies a place, returned from a Place Search.params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
input
— The text string on which to search. The Place Autocomplete service will return candidate matches based on this string and order results based on their perceived relevance.params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
input
— The text string on which to search. The Places service will return candidate matches based on this string and order results based on their perceived relevance.params
- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
This will return the status of the response send by google api. Use it after making any reqquest.
This will return the API KEY
been used with the requests.
This will set the API KEY
.
Feel free to report issues or make Pull Requests. If you find this document can be improved in any way, please feel free to open an issue for it.
The Google Places Api is open-sourced software licensed under the MIT license