百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

GeoLocation

> 编程语言
开源

使用 GeoLocation.php 获取边界坐标和距离

188 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 GeoLocation.php 获取边界坐标和距离

GeoLocation for PHP

GeoLocation for PHP offers convenient and easy to use methods for geocoding, geolocation and geometry functions in PHP.

Features include:

  1. Retrieve bounding box coordinates. Just define a coordinate and the size of your bounding box.
  2. calculate distances between geopoints/coordinates
  3. Solve point in polygon problems (identify whether a given point is within the bounds of a polygon)

Examples

Get distance between two points:

php
distanceTo($geopointB, 'miles');

Get latitude and longitude from address or location

In order to use this method, you'll need to register at Google Cloud Console and enable the Geocoding API

php
getLatitude();
$longitude = $geopoint->getLongitude();

Get bounding box coordinates

php
boundingBox(3, 'miles');
$boundingBox->getMaxLatitude();
$boundingBox->getMaxLongitude();
$boundingBox->getMinLatitude();
$boundingBox->getMinLongitude();

How to find if coordinates/geopoint are in a polygon.

php
inPolygon($polygon)) {
  echo "GeoPoint is in Polygon!";
}

Transform bounding box coordinates into a polygon

php
boundingBox(5, 'mi');
$polygon = $boundingBox->toPolygon();

and now you can check if the GeoPoint is the polygon / bounding box:

php
if ($geopointA->inPolygon($polygon)) {
  echo "GeoPoint is in Polygon / Bounding Box!";
}

Running Tests

Run the following from the project directory:

bash
./vendor/bin/phpunit tests

Credits and Legal

This is a collection of PHP classes written by Anthony Martin. Some of GeoLocation.php was derived from Java code that was originally published at

http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates.

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, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (c) 2019 Anthony Martin

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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言