Geo
in package
Please report bugs on https://github.com/matthiasmullie/geo/issues.
Tags
Table of Contents
Methods
- __construct() : mixed
- bounds() : Bounds
- This calculates the boundary at $distance north, east, south & west from $coord.
- distance() : float
- setRadius() : mixed
- Allows to override radius.
Methods
__construct()
public
__construct([mixed $unit = 'km' ]) : mixed
Parameters
- $unit : mixed = 'km'
-
e.g. km (kilometers) or mi (miles)
Tags
bounds()
This calculates the boundary at $distance north, east, south & west from $coord.
public
bounds(Coordinate $coord, float $distance) : Bounds
This can be used to easily query a database for coordinate within certain boundaries, like this: SELECT * FROM coordinates WHERE lat BETWEEN :swlat AND :nelat lng BETWEEN :swlng AND :nelng
:swlat being $bounds->sw->latitude :swlng being $bounds->sw->longitude :nelat being $bounds->ne->latitude :nelng being $bounds->ne->longitude
We only need 2 opposite corners in a rectangle to know all 4 boundaries, in this case the northeast & southwest coordinate. The northwest coordinate, for example, will have the same latitude as the southwest coordinate, and the same latitude as the northeast coordinate.
Parameters
- $coord : Coordinate
-
Coordinate to generate bounds for
- $distance : float
-
Distance in human readable format (e.g. km or mi)
Return values
Boundsdistance()
public
distance(Coordinate $coord1, Coordinate $coord2) : float
Parameters
- $coord1 : Coordinate
-
First coordinate
- $coord2 : Coordinate
-
Second coordinate
Tags
Return values
float —Actual distance in human readable format (e.g. km or mi)
setRadius()
Allows to override radius.
public
setRadius([mixed $radius = null ]) : mixed
If null, radius will be reset to the default for the given unit.
Parameters
- $radius : mixed = null