public function onBeforeWrite() { if (!$this->owner->isAddressChanged()) { return; } $address = $this->owner->getFullAddress(); $region = strtolower($this->owner->Country); if (!($point = GoogleGeocoding::address_to_point($address, $region))) { return; } $this->owner->Lat = $point['lat']; $this->owner->Lng = $point['lng']; }
/** * @param SQLQuery $query */ public function augmentSQL(SQLQuery &$query) { $address = Controller::curr()->getRequest()->getVar('Address'); if ($this->owner->hasMethod('updateAddressValue')) { $address = $this->owner->updateAddressValue($address); } if ($address) { // on frontend $coords = GoogleGeocoding::address_to_point($address); $Lat = $coords['lat']; $Lng = $coords['lng']; $query->addSelect(array('( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance')); } }
public function onBeforeWrite() { // TODO: Reinstate the checks below parent::onBeforeWrite(); // If the record doesn't have Lat/Lng OR the address has changed, get a new geolocation if (!$this->lat || !$this->lng || $this->isChanged('Address1')) { // If the record has an address, suburb and region, retrieve the geolocation (line 52) if ($this->Address1 && $this->Suburb && $this->Region) { // Get the member's address $address = $this->Address1 . ' ' . $this->Suburb . ' ' . $this->Region; //$address = $this->Address1; // Run it through GoogleGeocoding's address_to_point function (RestfulService/XML) $point = GoogleGeocoding::address_to_point($address); // Set the lat and lng values with the response $this->lat = $point['Latitude']; $this->lng = $point['Longitude']; } } }
public function onBeforeWrite() { if (!Config::inst()->get('Geocodable', 'is_geocodable')) { return; } if ($this->owner->LatLngOverride) { return; } if (!$this->owner->hasMethod('isAddressChanged') || !$this->owner->isAddressChanged()) { return; } $address = $this->owner->getFullAddress(); $region = strtolower($this->owner->Country); $point = GoogleGeocoding::address_to_point($address, $region); if (!$point) { return; } $this->owner->Lat = $point['lat']; $this->owner->Lng = $point['lng']; }
function convertAddressToPoint() { $records = LocatableMember::get(); foreach ($records as $record) { if (!$record->Latitude) { $address = $record->Address . " " . $record->Suburb . " " . $record->Region; $point = GoogleGeocoding::address_to_point($address); $record->Latitude = $point['Latitude']; $record->Longitude = $point['Longitude']; $record->write(); } } }
/** * @return bool|string */ public function getAddressSearchCoords() { if (!$this->request->getVar('Address')) { return false; } $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); $lat = $coords['lat']; $lng = $coords['lng']; return "defaultLat: {$lat}, defaultLng: {$lng},"; }