phpgeo ให้นามธรรมกับพิกัดทางภูมิศาสตร์ (รวมถึงการรองรับทรงรีที่แตกต่างกัน) และช่วยให้คุณสามารถคำนวณระยะทางทางภูมิศาสตร์ระหว่างพิกัดด้วยความแม่นยำสูง
เวอร์ชัน PHP ขั้นต่ำที่ต้องการคือ 8.1 phpgeo ได้รับการทดสอบจนถึง PHP 8.3
คุณสมบัติใหม่จะเข้าสู่สาขาหลักเท่านั้นและจะไม่ถูกแบ็คพอร์ต
สามารถติดตั้ง 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 โปรดดูรายการต่อไปนี้เพื่อดูว่ามีอะไรเปลี่ยนแปลงไปและสิ่งที่คุณต้องทำเพื่ออัปเกรดโค้ดของคุณ
เปลี่ยน | คำอธิบาย | การกระทำ |
---|---|---|
เมธอด setPoint1() และ setPoint2() ถูกลบออกจาก Line | คลาส Line ตอนนี้ไม่เปลี่ยนรูป | ใช้ Constructor เพื่อสร้างอินสแตนซ์ใหม่ของ 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)
หรือเรียกเมธอด getDistance()
ของวัตถุ Coordinate โดยการฉีดวัตถุเครื่องคิดเลข:
<?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)
Polylines สามารถทำให้ง่ายขึ้นเพื่อประหยัดพื้นที่เก็บข้อมูลหรือแบนด์วิดท์ การทำให้เข้าใจง่ายทำได้ด้วยอัลกอริทึม 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
เป็นไปได้ที่จะรันเมทริกซ์ทดสอบ CI ทั้งหมดภายในเครื่องด้วย act :
act --rm -P ubuntu-latest=shivammathur/node:latest