germania-kg/geodata
Composer 安装命令:
composer require germania-kg/geodata
包简介
Interfaces and traits for geo data
README 文档
README
Germania KG · GeoData
Installation
$ composer require germania-kg/geodata
Interfaces
GeoDataProviderInterface
<?php use Germania\GeoData\GeoDataProviderInterface;
/** * @return null|GeoDataInterface */ public function getGeoData();
GeoDataInterface
<?php use Germania\GeoData\GeoDataInterface;
/** * @return float|null */ public function getLatitude(); /** * @return float|null */ public function getLongitude(); /** * @return float[] */ public function getLatLon(); /** * @return string|null */ public function getSource(); /** * @return string|null */ public function getStatus();
Traits
GeoDataProviderTrait
The GeoDataProviderTrait provides a public geodata property as well as a getGeoData method prescribed by GeoDataProviderInterface:
<?php use Germania\GeoData\GeoDataProviderTrait; class MyGeoDataProvider { use GeoDataProviderTrait; } $object = new MyGeoDataProvider; // Property or GeoDataProviderInterface method $object->geodata; $object->getGeoData();
Classes
GeoDataAbstract
The GeoDataAbstract provides public latitude and longitude properties as well as the methods prescribed by GeoDataInterface:
<?php use Germania\GeoData\GeoDataAbstract; class MyGeoData extends GeoDataAbstract { use GeoDataTrait; } $object = new MyGeoData; // Properties echo $object->latitude; echo $object->longitude; // GeoDataProviderInterface methods echo $object->getLatitude(); echo $object->getLongitude(); $coords = $object->getLatLon();
GeoData
The GeoData class extends GeoDataAbstract and implements GeoDataInterface and also GeoDataProviderInterface:
<?php use Germania\GeoData\GeoData; // "Null" object $geo = new GeoData(); $coords = $object->getLatLon(); // [ null, null] $coords = $object->getLatitude(); // null $coords = $object->getLongitude(); // null echo $geo->getSource(); // null // With real data $latitude = 54.0; $longitude = 10.0; $description = "provided by Google Maps"; $geo = new GeoData( $latitude, $longitude, $description); $geo->setSource("Corrected manually"); $get->setStatus("Not too exact"); $coords = $object->getLatLon(); // [ 54.0, 10.0] echo $geo->getSource(); // "Corrected manually"
Factories
GeoDataFactory
The GeoDataFactory class provides a fromArray method:
<?php use Germania\GeoData\GeoDataFactory; use Germania\GeoData\GeoData; $factory = new GeoDataFactory; // All these fields default to null $geodata = $factory([ 'latitude' => 54, 'longitude' => 10, 'source' => "Test case", 'status' => "OK" ]);
GuzzleGeoDataFactory
The GuzzleGeoDataFactory is a client for Germania's Geocoding API. It implements StringGeoDataFactoryInterface and requires Guzzle, configured to ask Germania's GeoCoder API.
Sorry, the API is not public. You may use the Factory class to cook your own HTTP-client-based GeoData factory.
<?php use Germania\GeoData\GuzzleGeoDataFactory; use GuzzleHttp\Client as GuzzleClient; $guzzle = new GuzzleClient( ... ); $factory = new GuzzleGeoDataFactory($guzzle); $geodata = $factory->fromString("Musterstraße 1, 12345 Musterstadt"); echo get_class( $geodata ); // Germania\GeoData\GeoData
Exceptions: Just in case the Guzzle client throws an exception or the API response is invalid, watch out for these:
<?php use Germania\GeoData\GeoDataExceptionInterface; use Germania\GeoData\GeoDataFactoryRuntimeException; // For 404 ClientExceptions, extends GeoDataFactoryRuntimeException use Germania\GeoData\GeoDataFactoryNotFoundException;
Filters
NotEmptyGeoDataFilterIterator
Accepts any Traversable and filters for GeoDataInterface or GeoDataProviderInterface items whose getLatitude and getLongitude results are not empty.
Development
$ git clone https://github.com/GermaniaKG/Geodata.git
$ cd Geodata
$ composer install
Unit tests
Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit
germania-kg/geodata 适用场景与选型建议
germania-kg/geodata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 194 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 germania-kg/geodata 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 germania-kg/geodata 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 194
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-23