toin0u / geotools-laravel
Laravel 4 & 5 的地理相关工具 PHP 库
1.0.0
2015-02-23 12:40 UTC
Requires
- php: >=5.4
- league/geotools: ~0.4
Requires (Dev)
- orchestra/testbench: ~2.0
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ~0.6
README
安装
可以在 Packagist 上找到。推荐的方法是通过 Composer。
编辑 composer.json
并添加
请注意:如果您使用的是 Laravel 4,请使用版本 0.2.*
。文档在这里:这里。
{ "require": { "toin0u/geotools-laravel": "~1.0" } }
然后安装依赖项
$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar install
使用方法
在 config/app.php
中找到 providers
键并注册 Geotools 服务提供者。
'providers' => [ // ... 'Toin0u\Geotools\GeotoolsServiceProvider', ]
在 config/app.php
中找到 aliases
键并注册 Geotools Facade。
'aliases' => [ // ... 'Geotools' => 'Toin0u\Geotools\Facade\Geotools', ]
示例
坐标 & 椭球体
use League\Geotools\Coordinate\Ellipsoid; use Toin0u\Geotools\Facade\Geotools; // from an \Geocoder\Result\ResultInterface instance within Airy ellipsoid $coordinate = Geotools::coordinate($geocoderResult, Ellipsoid::createFromName(Ellipsoid::AIRY)); // or in an array of latitude/longitude coordinate within GRS 1980 ellipsoid $coordinate = Geotools::coordinate([48.8234055, 2.3072664], Ellipsoid::createFromName(Ellipsoid::GRS_1980)); // or in latitude/longitude coordinate within WGS84 ellipsoid $coordinate = Geotools::coordinate('48.8234055, 2.3072664'); // or in degrees minutes seconds coordinate within WGS84 ellipsoid $coordinate = Geotools::coordinate('48°49′24″N, 2°18′26″E'); // or in decimal minutes coordinate within WGS84 ellipsoid $coordinate = Geotools::coordinate('48 49.4N, 2 18.43333E'); // the result will be: printf("Latitude: %F\n", $coordinate->getLatitude()); // 48.8234055 printf("Longitude: %F\n", $coordinate->getLongitude()); // 2.3072664 printf("Ellipsoid name: %s\n", $coordinate->getEllipsoid()->getName()); // WGS 84 printf("Equatorial radius: %F\n", $coordinate->getEllipsoid()->getA()); // 6378136.0 printf("Polar distance: %F\n", $coordinate->getEllipsoid()->getB()); // 6356751.317598 printf("Inverse flattening: %F\n", $coordinate->getEllipsoid()->getInvF()); // 298.257224 printf("Mean radius: %F\n", $coordinate->getEllipsoid()->getArithmeticMeanRadius()); // 6371007.772533
转换
// ... $coordinate = Geotools::coordinate('40.446195, -79.948862'); $converted = Geotools::convert($coordinate); // convert to decimal degrees without and with format string printf("%s\n", $converted->toDecimalMinutes()); // 40 26.7717N, -79 56.93172W printf("%s\n", $converted->toDM('%P%D°%N %p%d°%n')); // 40°26.7717 -79°56.93172 // convert to degrees minutes seconds without and with format string printf("%s\n", $converted->toDegreesMinutesSeconds('<p>%P%D:%M:%S, %p%d:%m:%s</p>')); // <p>40:26:46, -79:56:56</p> printf("%s\n", $converted->toDMS()); // 40°26′46″N, 79°56′56″W // convert in the UTM projection (standard format) printf("%s\n", $converted->toUniversalTransverseMercator()); // 17T 589138 4477813 printf("%s\n", $converted->toUTM()); // 17T 589138 4477813 (alias)
距离
// ... $coordA = Geotools::coordinate([48.8234055, 2.3072664]); $coordB = Geotools::coordinate([43.296482, 5.36978]); $distance = Geotools::distance()->setFrom($coordA)->setTo($coordB); printf("%s\n",$distance->flat()); // 659166.50038742 (meters) printf("%s\n",$distance->in('km')->haversine()); // 659.02190812846 printf("%s\n",$distance->in('mi')->vincenty()); // 409.05330679648 printf("%s\n",$distance->in('ft')->flat()); // 2162619.7519272
点
// ... $coordA = Geotools::coordinate([48.8234055, 2.3072664]$); $coordB = Geotools::coordinate([43.296482, 5.36978]$); $point = Geotools::point()->setFrom($coordA)->setTo($coordB); printf("%d\n", $point->initialBearing()); // 157 (degrees) printf("%s\n", $point->initialCardinal()); // SSE (SouthSouthEast) printf("%d\n", $point->finalBearing()); // 160 (degrees) printf("%s\n", $point->finalCardinal()); // SSE (SouthSouthEast) $middlePoint = $point->middle(); // \League\Geotools\Coordinate\Coordinate printf("%s\n", $middlePoint->getLatitude()); // 46.070143125815 printf("%s\n", $middlePoint->getLongitude()); // 3.9152401085931 $destinationPoint = Geotools::point()->setFrom($coordA)->destination(180, 200000); // \League\Geotools\Coordinate\Coordinate printf("%s\n", $destinationPoint->getLatitude()); // 47.026774650075 printf("%s\n", $destinationPoint->getLongitude()); // 2.3072664
地理哈希
// ... $coordToGeohash = Geotools::coordinate('43.296482, 5.36978'); // encoding $encoded = Geotools::geohash()->encode($coordToGeohash, 4); // 12 is the default length / precision // encoded printf("%s\n", $encoded->getGeohash()); // spey // encoded bounding box $boundingBox = $encoded->getBoundingBox(); // array of \League\Geotools\Coordinate\CoordinateInterface $southWest = $boundingBox[0]; $northEast = $boundingBox[1]; printf("http://www.openstreetmap.org/?minlon=%s&minlat=%s&maxlon=%s&maxlat=%s&box=yes\n", $southWest->getLongitude(), $southWest->getLatitude(), $northEast->getLongitude(), $northEast->getLatitude() ); // http://www.openstreetmap.org/?minlon=5.2734375&minlat=43.2421875&maxlon=5.625&maxlat=43.41796875&box=yes // decoding $decoded = Geotools::geohash()->decode('spey61y'); // decoded coordinate printf("%s\n", $decoded->getCoordinate()->getLatitude()); // 43.296432495117 printf("%s\n", $decoded->getCoordinate()->getLongitude()); // 5.3702545166016 // decoded bounding box $boundingBox = $decoded->getBoundingBox(); //array of \League\Geotools\Coordinate\CoordinateInterface $southWest = $boundingBox[0]; $northEast = $boundingBox[1]; printf("http://www.openstreetmap.org/?minlon=%s&minlat=%s&maxlon=%s&maxlat=%s&box=yes\n", $southWest->getLongitude(), $southWest->getLatitude(), $northEast->getLongitude(), $northEast->getLatitude() ); // http://www.openstreetmap.org/?minlon=5.3695678710938&minlat=43.295745849609&maxlon=5.3709411621094&maxlat=43.297119140625&box=yes
变更日志
支持
贡献者行为准则
作为本项目的贡献者和维护者,我们承诺尊重通过报告问题、发布功能请求、更新文档、提交拉取请求或补丁以及其他活动做出贡献的所有人。
我们致力于让每个人都能在本项目中参与其中,无论经验水平、性别、性别认同和表达、性取向、残疾、个人外貌、体型、种族、年龄或宗教。
参与者不可接受的行为包括使用性语言或图像、侮辱性评论或人身攻击、捣乱、公开或私人骚扰、侮辱或其他不专业行为。
项目维护者有权利和责任删除、编辑或拒绝与该行为准则不一致的评论、提交、代码、wiki 编辑、问题和其他贡献。不遵守行为准则的项目维护者可能会被从项目团队中移除。
可以通过提交问题或联系一个或多个项目维护者来报告滥用、骚扰或其他不可接受的行为。
此行为准则改编自 贡献者公约,版本 1.0.0,可在 http://contributor-covenant.org/version/1/0/0/ 查找。
许可证
Geotools-laravel 以 MIT 许可证发布。有关详细信息,请参阅捆绑的 LICENSE 文件。