0

I'm trying to duplicate the answer to this question but in CakePHP 3: Search distance between 2 points CakePHP

How do I create virtual fields on the fly for CakePHP 3?

And here's my custom finder, which of course doesn't work because of the bad virtual field creation:

protected function findByDistance($lat, $long, $distance)
{
    $distanceValue = $this->calcDistance($lat, $long, $this->_properties['latitude'], $this->_properties['longitude']);
    $this->virtualFields['distance'] = $distanceValue;
    return $query->where(['distance <=' => $distance]);
}
Community
  • 1
  • 1
Naidim
  • 6,918
  • 2
  • 23
  • 20
  • 2
    see if [**this**](http://stackoverflow.com/questions/38462718/cakephp-query-closest-latitude-longitude-from-database/38522403#38522403) answer can help – arilia Mar 14 '17 at 13:32
  • Thank you, that was exactly what I needed. – Naidim Mar 15 '17 at 01:12

0 Answers0