I want to sort entries with a Smart Map address field for closest location. I know how it should be done in a template:
{% set entries = craft.entries.myAddress(params).order('distance').find() %}
Only, I would like to do so in my business logic and not in my template. I tried something like this.
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'houses';
$criteria->myAddress->target = '90210';
$criteria->order = 'myAddress.distance';
However, this does not work.
Is this possible? I tried related options but can't seem to get anything to work. Can I also do this with the Element API plugin to return the results as JSON?