imphinite/gaode-maps
Composer 安装命令:
composer require imphinite/gaode-maps
包简介
This is a php package for Gaode Web Services API
关键字:
README 文档
README
DEVELOPMENT IN PROGRESS
Provides convenient way of setting up and making requests to Gaode Web Services API from Laravel application.
For services documentation, API key and Usage Limits visit Gaode Web Services API and Gaode Web Services API Usage Limits And Restrictions.
**Note that this package is under development. Most Features are not implemented yet. Feel free to collaborate on this project!
**SPECIAL THANKS TO Alexpechkarev. Web Services Engine is borrowed from Alexpechkarev/google-maps.
Features
Features TO-DO List
- Geocoding/Reverse Geocoding API
- Directions API
- District Query API
- Geolocation API
- Roads API
- Static Maps API
- Coordinate Convert API
- Weather API
- Auto Complete API
- Traffic API
- Geofence API
Dependency
Installation
Issue following command in console:
composer require imphinite/gaode-maps
Alternatively edit composer.json by adding following line and run composer update
"require": { ...., "imphinite/gaode-maps", },
Configuration
Register package service provider and facade in 'config/app.php'
'providers' => [ ... 'GaodeMaps\ServiceProvider\GaodeMapsServiceProvider', ] 'aliases' => [ ... 'GaodeMaps' => 'GaodeMaps\Facade\GaodeMapsFacade', ]
Publish configuration file using php artisan vendor:publish --tag=gaodemaps --force or simply copy package configuration file and paste into config/gaodemaps.php
Open configuration file config/gaodemaps.php and add your service key
/* |---------------------------------- | Service Keys |------------------------------------ */ 'key' => 'YOUR GAODE API 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.
Usage
Here is an example of making request to Places Search API:
$service = GaodeMaps::load('nearbysearch') ->setParam([ 'location' => '120.392164,36.056936', // Longitude first in Chinese convention 'keywords' => '餐厅', 'radius' => 5000, 'page' => 1, 'extensions' => 'all', 'output' => 'json' ]); $response = $service->get(); ...
Alternatively parameters can be set using setParamByKey() method. For deeply nested array use "dot" notation as per example below.
$endpoint = GaodeMaps::load('nearbysearch') ->setParamByKey('location', '120.392164,36.056936') ->setParamByKey('keywords', '餐厅') //return $this ...
Another example showing request to Batch Request service when requesting multiple places' details:
$batch_urls = array(); array_push($batch_urls, (object) array( 'url' => GaodeMaps::load('placedetails') ->setParam(['id' => $place->id) ->getBatchUrl() ) ); $service = GaodeMaps::load('batchrequest') ->setParam([ 'ops' => $batch_urls ]); $response = $batch_service->get(); ...
Available methods
load( $serviceName ) - load web service by name
Accepts string as parameter, web service name as specified in configuration file.
Returns reference to it's self.
GaodeMaps::load('nearbysearch') ...
setParamByKey( $key, $value ) - set request parameter using key:value pair
Accepts two parameters:
key- body parameter namevalue- body parameter value
Deeply nested array can use 'dot' notation to assign value.
Returns reference to it's self.
$service = GaodeMaps::load('nearbysearch') ->setParamByKey('location', '120.392164,36.056936') ->setParamByKey('keywords', '餐厅') //return $this ...
setParam( $parameters ) - set all request parameters at once
Accepts array of parameters
Returns reference to it's self.
$service = GaodeMaps::load('nearbysearch') ->setParam([ 'location' => '120.392164,36.056936', // Longitude first in Chinese convension 'keywords' => '餐厅', 'radius' => 5000, 'page' => 1, 'extensions' => 'all', 'output' => 'json' ]); // return $this ...
getBatchUrl() - generate a Url of this service for Batch Request web service
Returns Batch Request url of this service.
$url = GaodeMaps::load('nearbysearch') ->setParam([ 'location' => '120.392164,36.056936', // Longitude first in Chinese convension 'keywords' => '餐厅', 'radius' => 5000, 'page' => 1, 'extensions' => 'all', 'output' => 'json' ])->getBatchUrl(); ...
get()- perform web service request (irrespectively to request type POST or GET )
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.
$response = GaodeMaps::load('nearbysearch') ->setParam([ 'location' => '120.392164,36.056936', // Longitude first in Chinese convension 'keywords' => '餐厅', 'radius' => 5000, 'page' => 1, 'extensions' => 'all', 'output' => 'json' ])->get(); var_dump(json_decode($response)); // output ... /* { "status": "1", "count": "274", "info": "OK", "infocode": "10000", "suggestion": { "keywords": [], "cities": [] }, "pois": [ "0": { "id": "B0FFFF4RX1", "tag": "牛道红花牛三品,菌类拼盘,新快猪上五花,牛舌厚切,石锅拌饭,红花三拼,红花牛芝士盖饭,烤蘑菇,红花牛肉,猪雪花肩胛肉,牛舌薄切,生拌牛肉,迷你现压朝鲜冷面,炒乌冬面,牛肩胛肉,酱香牛腿芯,海鲜饼,牛肋脊,泡菜饼,烤牛肉,牛仔骨,海鲜乌冬面,红花牛特色三样,烤五花肉,极品一口牛排", "name": "新快牛道红花牛馆(百丽广场店)", "type": "餐饮服务;中餐厅;特色/地方风味餐厅", ... */
MIT License
Collection of Gaode Web Services API for Laravel 5 is released under the MIT License.
imphinite/gaode-maps 适用场景与选型建议
imphinite/gaode-maps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「places api web service」 「Gaode maps api」 「Gaode web services api」 「China places api」 「laravel places api」 「高德 api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 imphinite/gaode-maps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imphinite/gaode-maps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 imphinite/gaode-maps 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Google integration settings and helpers for Laravel Enso
Model of a web-based resource
A PSR-7 compatible library for making CRUD API endpoints
Retrieve a WebResourceInterface instance over HTTP
Google Maps PHP SDK.
Modern Google Places API client for PHP
统计信息
- 总下载量: 45
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-18