-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathGeocodable.php
More file actions
46 lines (36 loc) · 983 Bytes
/
Copy pathGeocodable.php
File metadata and controls
46 lines (36 loc) · 983 Bytes
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
43
44
45
46
<?php
trait Geocodable {
/** @var string */
protected $address;
/** @var \Geocoder\Geocoder */
protected $geocoder;
/** @var \Geocoder\Result\Geocoded */
protected $geocoderResult;
public function setGeocoder(\Geocoder\Geocoder $geocoder)
{
$this->geocoder = $geocoder;
}
public function setAddress($address)
{
$this->address = $address;
}
public function getLatitude()
{
if (isset($this->geocoderResult) === false) {
$this->geocodeAddress();
}
return $this->geocoderResult->first()->getLatitude();
}
public function getLongitude()
{
if (isset($this->geocoderResult) === false) {
$this->geocodeAddress();
}
return $this->geocoderResult->first()->getLongitude();
}
protected function geocodeAddress()
{
$this->geocoderResult = $this->geocoder->geocode($this->address);
return true;
}
}