vovanmix/google-places-api
Composer 安装命令:
composer require vovanmix/google-places-api
包简介
Google Places Api
README 文档
README
This is a fork of https://github.com/SachinAgarwal1337/google-places-api.
I added model classes for results, API to retrieve photos, and caching.
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 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.
Installation
Install it with composer
composer require vovanmix/google-places-api
Usage
Laravel user can see the Laravel Usage section
Step 1 - Import the class using namespace
use Vovanmix\GoogleApi\PlacesApi;
Step 2 - Initiate the object
$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.
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 Vovanmix\GoogleApi\PlacesApi; function () { $googlePlaces = new PlacesApi('API_KEY') # line 1 $response = $googlePlaces->placeAutocomplete('some input'); # line 2 }
Use with Laravel
Step 1
Set up the service provider and facade in the config\app.php
'providers' => [ .... .... Vovanmix\GoogleApi\ServiceProvider::class, ]; 'aliases' => [ .... .... 'GooglePlaces' => Vovanmix\GoogleApi\Facade::class, ];
Step 2
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.
Set 3
Start using the package using Facade.
$response = GooglePlaces::placesAutocomplete('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 Collecton 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
radiusmust 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, ortypesis required. params- Optionan Parameters You can refer all the avaiable 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- Optionan Parameters You can refer all the avaiable 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- 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.
Place Details
placeDetails($placeId, $params = [])
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
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- Optionan Parameters You can refer all the avaiable 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- Optionan Parameters You can refer all the avaiable optional parameters on the Google's Official Webpage
Additional Methods
getStatus()
This will return the status of the response send by google api. Use it after making any reqquest.
getKey()
This will return the API KEY been used with the requests.
setKey($key)
This will set the API KEY.
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
vovanmix/google-places-api 适用场景与选型建议
vovanmix/google-places-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 128 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「places」 「google api」 「google places」 「Google Places Api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vovanmix/google-places-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vovanmix/google-places-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vovanmix/google-places-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Google integration settings and helpers for Laravel Enso
A PSR-7 compatible library for making CRUD API endpoints
Google Maps PHP SDK.
Modern Google Places API client for PHP
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
统计信息
- 总下载量: 128
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-04