meetme/php-geopoint

GeoPoint是PHP的地理点实现

1.0 2016-02-16 03:17 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:58:41 UTC


README

GeoPoint代表PHP的地理点,包括转换、点对点距离和边界框计算。

使用方法

$statueOfLibertyPoint = new GeoPoint(40.689604, -74.04455, GeoPoint::DEGREES);

构造函数选项

  • latitude -- 纬度
  • longitude -- 经度
  • format -- 传入的经纬度格式的GeoPoint::DEGREES或GeoPoint::RADIANS

方法

  • getLatitude(): 返回点的纬度,格式为点的格式(GeoPoint::DEGREES或GeoPoint::RADIANS)
  • getLongitude(): 返回点的经度,格式为点的格式(GeoPoint::DEGREES或GeoPoint::RADIANS)
  • distanceTo(GeoPoint, kmOrMiles): 使用GeoPoint::KILOMETERS或GeoPoint::MILES计算到另一个GeoPoint实例的距离。
  • boundingCoordinates(distance, radius, kmOrMiles): 计算从点出发的距离为distance的边界坐标,并返回一个包含边界框的SW和NE点的数组。如果未提供radius,则使用地球半径。距离以公里计算,除非kmOrMiles设置为GeoPoint::MILES。

静态方法

  • GeoPoint::degreesToRadians(value): 将度值转换为弧度
  • GeoPoint::radiansToDegrees(value): 将弧度值转换为度
  • GeoPoint::milesToKilometers(value): 将英里值转换为公里
  • GeoPoint::kilometersToMiles(value): 将公里值转换为英里

运行测试

php composer.phar test

致谢

背景

这是受到David Wood的JavaScript端口的启发,该端口基于Jan Philip Matuschek的Java代码,该代码在Jan Philip MatuschekFinding Points Within a Distance of a Latitude/Longitude Using Bounding Coordinates中展示。

作者/贡献者

许可证

The MIT License

Copyright (c) 2016 MeetMe, Inc. http://www.meetmecorp.com/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.