masterskill / afa-api-laravel
A package for the AFA Code API Integration, that needs to interacts with it's database and existing database
Installs: 31
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.2
- spatie/laravel-package-tools: ^1.16
README
API v0.2.1 from the AFACodes
Endpoints and functionalities of the Logistic Grid, syntax “CM-$etc”. For Scientific Grid (syntax “CM+$etc”) and covers, see next documentation. We use, instead a Swagger, the “page endpoint” that is self-explanatory.
Installation
With composer
composer require masterskill/afa-code-laravel
City Querying
For querying a city, you should initialize the cityQuery class.
Make sure you have the App\Models\City on the project.
use Masterskill\AfaApiLaravel\Domains\Http\City\CityQuery; $cityQuery = new CityQuery(); $query ="CM-SOA"; $result = $cityQuery->query($query); print_r($cityQuery);
Level
For the level correspondance, it depends on the side you want it.
From application, we use all these level, that is all the point of view from the user :
- 180 : 1m
- 155 : 6m
- 130 : 30m
- 105 : 200m
- 80 : 1km
Side
From AFACode, there is no level defined. Instead, they use side for the point of view.
With that, we need to make sure we transform all level into side
Below the SIDE and LEVEL relation.
- 0.5 : 180
- 2.5 : 155
- 16 : 130
- 90.5 : 105
- 512 : 80
To push it a little further, below the calculation.
switch (($side)) { case $side < 2.5: return 180; case 2.5 <= $side && $side < 15: return 155; case 15 <= $side && $side < 100: return 130; case 100 <= $side && $side < 600: return 105; case 600 <= $side: return 80; }
Centroid
Each city or point in the API will be assigned a centroid. This centroid can be used everywhere, but you can be sure there is always this centroid. You can calculate the centroid of point dirrectly too, but make sure to have the coordinatees in form of an array of lon / lat object.
To calculate it manually, you have the helper \Masterskill\AfaApiLaravel\Helpers\Centroide
, and call calculateCentroid
method statically.
Cell
A cell is a portion of territory in the AFACode API. You can get the cell either with the longitude and lattitude or directly with the BANOC code directly, both will generate a cell. The difference is that we often use the BANOC Code if we search a city or something we know the format, and we use the GeoQuery if we want to use a lon / lat format.
Make sure you instanciate the CellByGeoQuery
class before using it.
When you pass the lon and lat and eventually the level, for exemple lon : 11.20524 and lat : 1.6580, it will be processed to make sure that the request will be valid in the AFACode API.
Thanks
Thanks for AFACode for their beautifull API. You can check their tools at https://afa.codes.
For example, in Yaoundé region, we can have https://afa.codes/CM-YE4-6DS