-
Notifications
You must be signed in to change notification settings - Fork 27
/
FactualCircle.php
42 lines (37 loc) · 1.11 KB
/
FactualCircle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Factual;
/**
* Represents a geographic sub query confining results to a circle.
* This is a refactoring of the Factual Driver by Aaron: https://github.com/Factual/factual-java-driver
* @author Tyler
* @package Factual
* @license Apache 2.0
*/
class FactualCircle {
private $lat;
private $lon;
private $meters;
/**
* Constructs a geographic Circle representation.
* @param real lat the latitude of the center of this Circle.
* @param real lon the longitude of the center of this Circle.
* @param int metersRadius the radius, in meters, of this Circle.
*/
public function __construct($lat, $lon, $meters) {
if (!is_numeric($lat) || !is_numeric($lon)){
throw new \Exception("Cannot create FactualCircle: bad lat/lon parameters: lat='".$lat."',lon='".$lon."'");
return false;
}
$this->lat = $lat;
$this->lon = $lon;
$this->meters = $meters;
}
/**
* Returns JSON component of point-radius query
* @return string
*/
public function toJsonStr() {
return "{\"\$circle\":{\"\$center\":[" . $this->lat . "," . $this->lon . "],\"\$meters\":" . $this->meters . "}}";
}
}
?>