, (*1)
Google Places API.
A Laravel/Lumen package for working with Google API Web Services., (*2)
The following place requests are available:
-
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.
-
Place Add can be used to add a place to Google's Place database
Installation
Install it with composer, (*3)
composer require mrjonleek/laravel-google-api
Usage
Step 1
Set up the service provider and facade in the config\app.php, (*4)
'providers' => [
....
....
Mrjonleek\GoogleApi\Providers\PlacesServiceProvider::class,
];
'aliases' => [
....
....
'GooglePlaces' => Mrjonleek\GoogleApi\Facades\Places::class,
];
Step 2
publish the config file with following artisan command, (*5)
php artisan vendor:publish --provider="Mrjonleek\GoogleApi\Providers\PlacesServiceProvider"
This will create google.php file in the config directory., (*6)
Set the API KEY in this config file or in .env
as GOOGLE_API_KEY., (*7)
Set 3
Start using the package using Facade., (*8)
$response = GooglePlaces::placeAutocomplete('some city');
Response
The response returned is a Laravel's Collection so that you can perform any of the available collection methods on it., (*9)
Available Methods
, (*10)
Place Search
nearbySearch($location, $radius = null, $params = [])
-
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 if rankby=distance
(described under Optional parameters below) is specified.
- If
rankby=distance
(described under Optional parameters below) is specified, then one or more of keyword
, name
, or types
is required.
-
params
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
textSearch($query, $params = [])
-
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
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
radarSearch($location, $radius, array $params)
-
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
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
Note: A Radar Search request must include at least one of keyword
, name
, or types
., (*11)
, (*12)
Place Details
placeDetails($placeId, $params = [])
-
placeId
โ A textual identifier that uniquely identifies a place, returned from a Place Search.
-
params
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
, (*13)
Place Autocomplete
-
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
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
, (*14)
Query Autocomplete
-
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
- Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage
, (*15)
Place Add
addPlace($params)
Additional Methods
getStatus()
This will return the status of the response send by google api. Use it after making any request., (*16)
getKey()
This will return the API KEY
been used with the requests., (*17)
setKey($key)
This will set the API KEY
., (*18)
Contribution
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., (*19)
License
The Google Places Api is open-sourced software licensed under the MIT license, (*20)