Collection of Gaode Web Services API for Laravel 5
DEVELOPMENT IN PROGRESS, (*1)
Provides convenient way of setting up and making requests to Gaode Web Services API from Laravel application., (*2)
For services documentation, API key and Usage Limits visit Gaode Web Services API and Gaode Web Services API Usage Limits And Restrictions., (*3)
**Note that this package is under development. Most Features are not implemented yet. Feel free to collaborate on this project!, (*4)
**SPECIAL THANKS TO Alexpechkarev. Web Services Engine is borrowed from Alexpechkarev/google-maps., (*5)
Features
Features TO-DO List
Dependency
Installation
Issue following command in console:, (*6)
composer require imphinite/gaode-maps
Alternatively edit composer.json by adding following line and run composer update
, (*7)
"require": {
....,
"imphinite/gaode-maps",
},
Configuration
Register package service provider and facade in 'config/app.php', (*8)
'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
, (*9)
Open configuration file config/gaodemaps.php
and add your service key, (*10)
/*
|----------------------------------
| 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., (*11)
Usage
Here is an example of making request to Places Search API:, (*12)
$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., (*13)
$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:, (*14)
$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, (*15)
Accepts string as parameter, web service name as specified in configuration file.
Returns reference to it's self., (*16)
GaodeMaps::load('nearbysearch')
...
setParamByKey( $key, $value )
- set request parameter using key:value pair, (*17)
Accepts two parameters:
* key
- body parameter name
* value
- body parameter value, (*18)
Deeply nested array can use 'dot' notation to assign value.
Returns reference to it's self., (*19)
$service = GaodeMaps::load('nearbysearch')
->setParamByKey('location', '120.392164,36.056936')
->setParamByKey('keywords', '้คๅ
') //return $this
...
setParam( $parameters )
- set all request parameters at once, (*20)
Accepts array of parameters
Returns reference to it's self., (*21)
$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, (*22)
Returns Batch Request url of this service., (*23)
$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 ), (*24)
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., (*25)
$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., (*26)