phpgeo는 지리적 좌표에 대한 추상화(다양한 타원체 지원 포함)를 제공하며 좌표 간 지리적 거리를 매우 정확하게 계산할 수 있도록 해줍니다.
최소 필수 PHP 버전은 8.1입니다. phpgeo는 PHP 8.3까지 테스트되었습니다.
새로운 기능은 기본 분기에만 적용되며 백포트되지 않습니다.
이전 PHP 버전에는 이전 버전의 phpgeo를 설치할 수 있습니다. 호환성 매트릭스는 다음 표를 참조하십시오.
PHP 버전 | phpgeo 버전 | 지원현황 | 작곡가 설치 |
---|---|---|---|
8.3 | 5.x | 활동적인 | composer require mjaschen/phpgeo |
8.2 | 5.x | 활동적인 | composer require mjaschen/phpgeo |
8.1 | 5.x | 활동적인 | composer require mjaschen/phpgeo |
8.0 | 4.x | composer require mjaschen/phpgeo:^4.0 | |
7.4 | 4.x | composer require mjaschen/phpgeo:^4.0 | |
7.3 | 4.x | composer require mjaschen/phpgeo:^4.0 | |
7.2 | 3.x | 인생의 끝 | composer require mjaschen/phpgeo:^3.0 |
7.1 | 2.x | 인생의 끝 | composer require mjaschen/phpgeo:^2.0 |
7.0 | 2.x | 인생의 끝 | composer require mjaschen/phpgeo:^2.0 |
5.6 | 1.x | 인생의 끝 | composer require mjaschen/phpgeo:^1.0 |
5.5 | 1.x | 인생의 끝 | composer require mjaschen/phpgeo:^1.0 |
5.4 | 1.x | 인생의 끝 | composer require mjaschen/phpgeo:^1.0 |
문서는 phpgeo.marcusjaschen.de에서 확인할 수 있습니다.
Composer를 사용하여 다음을 실행하여 composer.json
에 추가하면 됩니다.
composer require mjaschen/phpgeo
프로젝트의 composer.json
에서 버전 제약 조건을 업데이트하고 다음을 실행하여 composer update
실행하거나 새 버전을 요구합니다.
composer require mjaschen/phpgeo:^5.0
phpgeo 에는 5.x 릴리스 라인에 몇 가지 주요 변경 사항이 있습니다. 변경된 사항과 코드를 업그레이드하기 위해 수행해야 할 작업을 확인하려면 다음 목록을 참조하세요.
변화 | 설명 | 행동 |
---|---|---|
Line 에서 setPoint1() 및 setPoint2() 메서드가 제거되었습니다. | 이제 Line 클래스는 변경할 수 없습니다. | 생성자를 사용하여 Line 의 새 인스턴스를 만듭니다. |
PHP 7.3, 7.4 및 8.0에 대한 지원이 제거되었습니다. | 이전 PHP 버전은 더 이상 지원되지 않습니다. | PHP 8.1 이상으로 업그레이드하세요. |
버전 2.0.0부터 phpgeo는 MIT 라이센스에 따라 라이센스가 부여됩니다. 이전 버전은 GPL 라이센스를 받았습니다.
정보: 많은 예제가 포함된 완전한 최신 문서를 보려면 문서 사이트를 방문하세요!
phpgeo는 다음 기능을 제공합니다(예제 링크를 따르세요):
18° 54′ 41″ -155° 40′ 42″
)이 목록은 불완전합니다. 전체 문서와 예제를 보려면 문서 사이트를 방문하세요!
계산기 개체를 직접 사용합니다.
<?php
use Location Coordinate ;
use Location Distance Vincenty ;
$ coordinate1 = new Coordinate ( 19.820664 , - 155.468066 ); // Mauna Kea Summit
$ coordinate2 = new Coordinate ( 20.709722 , - 156.253333 ); // Haleakala Summit
$ calculator = new Vincenty ();
echo $ calculator -> getDistance ( $ coordinate1 , $ coordinate2 ); // returns 128130 . 850 (meters ; ≈ 128 kilometers)
또는 계산기 개체를 삽입하여 Coordinate 개체의 getDistance()
메서드를 호출합니다.
<?php
use Location Coordinate ;
use Location Distance Vincenty ;
$ coordinate1 = new Coordinate ( 19.820664 , - 155.468066 ); // Mauna Kea Summit
$ coordinate2 = new Coordinate ( 20.709722 , - 156.253333 ); // Haleakala Summit
echo $ coordinate1 -> getDistance ( $ coordinate2 , new Vincenty ()); // returns 128130 . 850 (meters ; ≈ 128 kilometers)
폴리라인을 단순화하여 저장 공간이나 대역폭을 절약할 수 있습니다. 단순화는 Ramer–Douglas–Peucker 알고리즘(AKA Douglas-Peucker 알고리즘)을 사용하여 수행됩니다.
<?php
use Location Coordinate ;
use Location Polyline ;
use Location Distance Vincenty ;
$ polyline = new Polyline ();
$ polyline -> addPoint ( new Coordinate ( 10.0 , 10.0 ));
$ polyline -> addPoint ( new Coordinate ( 20.0 , 20.0 ));
$ polyline -> addPoint ( new Coordinate ( 30.0 , 10.0 ));
$ processor = new Simplify ( $ polyline );
// remove all points which perpendicular distance is less
// than 1500 km from the surrounding points .
$ simplified = $ processor -> simplify ( 1500000 );
// simplified is the polyline without the second point ( which
// perpendicular distance is ~ 1046 km and therefore below
// the simplification threshold)
phpgeo에는 점이 포함되어 있는지 여부를 결정하는 데 사용할 수 있는 다각형 구현이 있습니다. 다각형은 최소한 세 개의 점으로 구성됩니다. 포인트는 Coordinate
클래스의 인스턴스입니다.
경고: 다각형의 180/-180도 자오선 양쪽에 점이 있으면 계산 결과가 잘못됩니다.
<?php
use Location Coordinate ;
use Location Polygon ;
$ geofence = new Polygon ();
$ geofence -> addPoint ( new Coordinate (- 12.085870 ,- 77.016261 ));
$ geofence -> addPoint ( new Coordinate (- 12.086373 ,- 77.033813 ));
$ geofence -> addPoint ( new Coordinate (- 12.102823 ,- 77.030938 ));
$ geofence -> addPoint ( new Coordinate (- 12.098669 ,- 77.006476 ));
$ outsidePoint = new Coordinate (- 12.075452 , - 76.985079 );
$ insidePoint = new Coordinate (- 12.092542 , - 77.021540 );
var_dump ( $ geofence -> contains ( $ outsidePoint )); // returns bool ( false ) the point is outside the polygon
var_dump ( $ geofence -> contains ( $ insidePoint )); // returns bool ( true ) the point is inside the polygon
다양한 스타일로 좌표 형식을 지정할 수 있습니다.
<?php
use Location Coordinate ;
use Location Formatter Coordinate DecimalDegrees ;
$ coordinate = new Coordinate ( 19.820664 , - 155.468066 ); // Mauna Kea Summit
echo $ coordinate -> format ( new DecimalDegrees ());
<?php
use Location Coordinate ;
use Location Formatter Coordinate DMS ;
$ coordinate = new Coordinate ( 18.911306 , - 155.678268 ); // South Point , HI , USA
$ formatter = new DMS ();
echo $ coordinate -> format ( $ formatter ); // 18° 54′ 41″ -155° 40′ 42″
$ formatter -> setSeparator ( " , " )
-> useCardinalLetters ( true )
-> setUnits ( DMS :: UNITS_ASCII );
echo $ coordinate -> format ( $ formatter ); // 18° 54' 41" N , 155° 40 ' 42" W
<?php
use Location Coordinate ;
use Location Formatter Coordinate GeoJSON ;
$ coordinate = new Coordinate ( 18.911306 , - 155.678268 ); // South Point , HI , USA
echo $ coordinate -> format ( new GeoJSON ()); // { " type " : " point " , " coordinates " : [ -155.678268, 18.911306 ] }
끌어오기 요청을 제출하기 전에 모든 검사와 테스트를 실행하고 모든 것이 녹색인지 확인하세요.
composer ci:lint
composer ci:psalm
composer ci:tests
모든 검사와 테스트를 한 번에 실행하려면 composer ci
사용하세요.
물론, 테스트 실행기를 직접 사용할 수도 있습니다(예: PHPUnit의 경우).
./vendor/bin/phpunit
찬송가:
./vendor/bin/psalm
act를 사용하여 전체 CI 테스트 매트릭스를 로컬에서 실행할 수 있습니다.
act --rm -P ubuntu-latest=shivammathur/node:latest