1 | <?php |
||
18 | class GeoPoint implements JsonSerializable |
||
19 | { |
||
20 | /** |
||
21 | * geo point value, stored as associative array |
||
22 | * |
||
23 | * @ORM\Column(type="array", nullable=true) |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $point; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | * |
||
32 | * @param float $lat Latitude |
||
33 | * @param float $lng Longitude |
||
34 | */ |
||
35 | 5 | public function __construct($lat = null, $lng = null) |
|
48 | |||
49 | /** |
||
50 | * return elasticsearch-friendly geo point format. |
||
51 | * |
||
52 | * Beware: Elastic uses lat/lon as keys. Google uses lat/lng. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | 3 | public function toElastic() |
|
57 | { |
||
58 | 3 | if (empty($this->point)) { |
|
59 | 1 | return []; |
|
60 | } |
||
61 | |||
62 | return [ |
||
63 | 2 | 'lat' => $this->point['lat'], |
|
64 | 2 | 'lon' => $this->point['lng'], |
|
65 | 2 | ]; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Array representation of the geo point |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | 4 | public function toArray() |
|
77 | |||
78 | /** |
||
79 | * Implement json serializable interface. |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | 1 | public function jsonSerialize() |
|
87 | |||
88 | /** |
||
89 | * String representation of the point, lat lng order, separated by a space. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 1 | public function __toString() |
|
101 | } |
||
102 |