I'm using the Element API plugin to try and search for addresses using minimum and maximum lat & lng values and then using target element within the criteria parameters to filter the results however it doesn't seem to be working based on the code below.
$locationCriteria = craft()->elements->getCriteria('Entry');
$locationCriteria->lat = array('and', '>='.$max_min_values['min_latitude'], '<='.$max_min_values['max_latitude']);
$locationCriteria->long = array('and', '>='.$max_min_values['min_longitude'], '<='.$max_min_values['max_longitude']);
$locations = $locationCriteria->find();
return [
'criteria' => [
'section' => 'xxx',
'relatedTo' => [
'and',
['targetElement' => $locations],
]
],
'elementType' => ElementType::Entry,
'transformer' => new Search(),
];
Does anyone have any ideas?
array('and', '>='.$max_min_values['min_latitude'], '>='.$max_min_values['max_latitude']);
will get you only records with a latitude >= max latitude. The second thing: it's better to use$locationCriteria->ids()
since you don't need to populate the models. Performance wise using find in that manner is wasted