All Projects → SachinAgarwal1337 → Google Places Api

SachinAgarwal1337 / Google Places Api

Licence: mit
This is a PHP wrapper for Google Places API Web Service. And is Laravel Framework friendly.

Projects that are alternatives of or similar to Google Places Api

Figma To Google Slides
Convert Figma frames into a Google Slides presentation 🍭
Stars: ✭ 385 (+161.9%)
Mutual labels:  google-api, google
Laravel Google Ads
Google Ads API for Laravel
Stars: ✭ 56 (-61.9%)
Mutual labels:  google, laravel
Laravel Google Calendar
Manage events on a Google Calendar
Stars: ✭ 787 (+435.37%)
Mutual labels:  google, laravel
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (+76.19%)
Mutual labels:  google, laravel
Laravel Amp
Package that helps you set up AMP (Accelerated Mobile Pages) using Laravel
Stars: ✭ 106 (-27.89%)
Mutual labels:  google, laravel
Laravel Google Drive Demo
Laravel & Google Drive Storage - Demo project with Laravel 5.4
Stars: ✭ 299 (+103.4%)
Mutual labels:  google, laravel
Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
Stars: ✭ 1,026 (+597.96%)
Mutual labels:  google, laravel
Laravel Analytics
A Laravel package to retrieve pageviews and other data from Google Analytics
Stars: ✭ 2,613 (+1677.55%)
Mutual labels:  google, laravel
Google Api Nodejs Client
Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
Stars: ✭ 9,722 (+6513.61%)
Mutual labels:  google-api, google
Php Google Contacts V3 Api
👥 PHP library for the Google Contacts API (v3)
Stars: ✭ 97 (-34.01%)
Mutual labels:  google-api, google
React Native Google Sign In
React Native Wrapper for Latest Google Sign-In OAuth SDK / API
Stars: ✭ 213 (+44.9%)
Mutual labels:  google-api, google
Laravel Natural Language
This package makes using the Google Natural API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 119 (-19.05%)
Mutual labels:  google, laravel
Gam
command line management for Google Workspace
Stars: ✭ 2,558 (+1640.14%)
Mutual labels:  google-api, google
Raccoon4
APK Downloader for Google Play
Stars: ✭ 369 (+151.02%)
Mutual labels:  google-api, google
Psgsuite
Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
Stars: ✭ 184 (+25.17%)
Mutual labels:  google-api, google
Geocoder
🌎 GoLang package that provides an easy way to use the Google Geocoding API
Stars: ✭ 23 (-84.35%)
Mutual labels:  google-api, google
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (+801.36%)
Mutual labels:  google, laravel
Google Maps React
Companion code to the "How to Write a Google Maps React Component" Tutorial
Stars: ✭ 1,542 (+948.98%)
Mutual labels:  google-api, google
Ng Gapi
ng-gapi a Google api module for Angular 6+
Stars: ✭ 126 (-14.29%)
Mutual labels:  google-api, google
Google2csv
Google2Csv a simple google scraper that saves the results on a csv/xlsx/jsonl file
Stars: ✭ 145 (-1.36%)
Mutual labels:  google

Latest Stable Version Latest Unstable Version Total Downloads License

Google Places API.

This is a PHP wrapper for Google Places API Web Service. And is Laravel Framework friendly.

About Package

With just 2 lines of code you can request to any google places api feature. No need to manually perform any curl requests.

The following place requests are available:

  • Place Search This service gives a list of places based on a user's location or search string.
  • Place Details This service gives more detailed information about a specific Place, including user reviews.
  • Place Autocomplete This service is Used to automatically fill in the name and/or address of a place as you type.
  • Query Autocomplete This service is Used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
  • Place Photo This gives you access to the millions of photos stored in the Google's Places database
  • Custom Headers Set Custom Headers.
  • Additional Methods Additional Methods Available.

Installation

Install it with composer

composer require skagarwal/google-places-api

Usage

Laravel user can see the Laravel Usage section

Step 1 - Import the class using namespace

use SKAgarwal\GoogleApi\PlacesApi;

Step 2 - Initiate the object

$googlePlaces = new PlacesApi('API KEY');

Note: You can also set the API KEY after initiating the class using setKey('KEY') method. You can chain this with method with any other methods.

Step 3 - Start Using the Api.

Example:

$response = $googlePlaces->placeAutocomplete('some Place');

As mentioned earlier just 2 lines of code to make any request.

Full example:

use SKAgarwal\GoogleApi\PlacesApi;


function () {
  $googlePlaces = new PlacesApi('API_KEY') # line 1
  $response = $googlePlaces->placeAutocomplete('some input'); # line 2
}


Use with Laravel

For Laravel 5.5

Auto Discovery added.

For Laravel 5.4 and below

Step 1

Set up the service provider and facade in the config\app.php

'providers' => [
....
....
SKAgarwal\GoogleApi\ServiceProvider::class,
];

'aliases' => [
....
....
'GooglePlaces' => SKAgarwal\GoogleApi\Facade::class,
];

Step 2

publish the config file with following artisan command

php artisan vendor:publish --provider="SKAgarwal\GoogleApi\ServiceProvider"

This will create google.php file in the config directory.

Set the API KEY in this config file.

Set 3

Start using the package using Facade.

$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.

If you are not familiar with Laravel's Collection you can either reference the docs here or you can use response as simple array.

Available Methods

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

findPlace($input, $inputType, $params = [])

  • input — The text input specifying which place to search for (for example, a name, address, or phone number).
  • inputType — The type of input. This can be one of either textquery or phonenumber. Phone numbers must be in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself).
  • params - Optional Parameters You can refer all the available optional parameters on the Google's Official Webpage

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

Place Autocomplete

placeAutocomplete($input, $params = [])

  • 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

Query Autocomplete

queryAutocomplete($input, $params = [])

  • 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

Place Photo

photo($photoReference, $params = [])


Custom Headers

withHeaders(array $headers)

Call This method before any other methods to set the headers. You can chain this method.

new PlacesApi($key = null, $verifySSL = true, array $headers = [])

To have custom headers set for every call, you can pass 3rd parameter as the headers to class constructor.

Note: For Laravel Users, you can set this in config file with key headers


Additional Methods

getStatus()

This will return the status of the response send by google api. Use it after making any request.

getKey()

This will return the API KEY been used with the requests.

setKey($key)

This will set the API KEY.

verifySSL($verifySSL = true)

You can pass false to disable Verification of SSL Certification.

Note: For Laravel Users, you can set this in config file with key verify_ssl

Or You can Pass the path to the certificate.

Exceptions

Google Places API may throw various exceptions based on the given $params or response and is located in the SKAgarwal\GoogleApi\Exceptions namespace.

  • A GooglePlacesApiException is thrown when no API KEY is provided or $params is invalid. Note: This is the parent class for the preceding exceptions.
  • A InvalidRequestException is thrown when the response status is INVALID_REQUEST
  • A OverQueryLimitException is thrown when the response status is OVER_QUERY_LIMIT
  • A RequestDeniedException is thrown when the response status is REQUEST_DENIED
  • A UnknownErrorException is thrown when the response status is UNKNOWN_ERROR
  • A NotImplementedException is thrown when the response cannot be determined.

If any of these exception has been thrown, you can use the getErrorMessage() method to get the error_message field from the response if any is provided. Note: error_message field is not guaranteed to be always present, and its content is subject to change.

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.

License

The Google Places Api is open-sourced software licensed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].