imphinite / gaode-maps
This is a php package for Gaode Web Services API
Installs: 45
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:laravel
Requires
- illuminate/support: 5.*
This package is not auto-updated.
Last update: 2025-05-11 07:06:10 UTC
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.