Mfilter2 creating a custom filter to filter on radius

Hello, could someone please help me with mfilter2?
I created a custom filter, to filter on distance, but I think I do something wrong.

I looked at this example, but I think I miss something or maybe think to complicated:
https://docs.modx.pro/en/components/msearch2/extension/items-filtration-example

Does the method filterMethod, run for each item?
I created a simple buildMethod function:

public function buildRangeFilter(array $values, $name = '') {
		return array(
			array(
				'title' => "Locatie zoeken",
				'value' => $values[0],
				'type' => 'string',
				'resources' => [],
				'name' => $name,
			)
		);
	}

It creates a textfield…
I type in Amsterdam in the textfield,

Then I get Amsterdam in mij filterMethod:

public function filterRange(array $requested, array $values, array $ids) {
		$matched = array();

		$latlong = $this->getLatLongByCity($requested[0]);

		$pdo = $this->modx->getService('pdoFetch');
		$found = $pdo->getCollection(
			'modResource',
			[
				'published' => 1,
				'deleted' => 0
			],
			[
				'resources' => $ids,
				'having' => 'afstand < 1000',
				'includeTVs' => 'ubeeo_latitude,ubeeo_longitude',
				'sortby' => 'publishedon',
				'sortdir' => 'ASC',
				'limit' => 9999,
				'depth' => 0,
				'returnIds' => 1,
				'select' => [
					'modResource' => 'id',
					'afstand' => '( 6371 * acos( cos( radians(52.010269) ) * cos( radians( `TVubeeo_latitude`.`value` ) ) * cos( radians( `TVubeeo_longitude`.`value` ) - radians('.$latlong['long'].') ) + sin( radians('.$latlong['lat'].') ) * sin( radians( `TVubeeo_latitude`.`value` ) ) ) ) AS `afstand`'
				]
			]
		);

		foreach($found as $resource) {
			$matched[] = $resource['id'];
		}

		return $matched;
	}

there I want to get all resources that have the correct distance, but that method is loaded for each resource?
It is so strange…

Maybe I need to use another way to do this? I can not really use the direct field, I need to do a custom function to calculate the distance, and based on that, return the filtered items.

I am already trying this and debugging this for days now and could really use some guidance.

this is my complete call: (Fenom tags)

{$_modx->runSnippet('mFilter2', [
	'element'=>'pdoResources',
'showEmptyFilters' => 1,
'limit' => 99999,
'parents'=> $_modx->config['ubeeo_vacancy_parent'],
'resources'=> -$_modx->config['vacature_notfound-resource'],
'tplWrapper' => '@INLINE <h2 class="heading-h4"><span id="vac-counter">{$total}</span> Gevonden</h2>{$output}',
'tpl'=>'@INLINE <article class="cell vacancy">
						<a href="{$id | url}" title="{$pagetitle}">
							<div class="content">
								<header>
									<h1 class="heading-h3">{$pagetitle}</h1>
								</header>
								<div class="details">
                                    {if $ubeeo_city}
										<span class="location">
                                    <svg width="11" height="16" viewBox="0 0 11 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                        <path d="M5.33334 0C2.39259 0 0 2.39259 0 5.33334C0 6.21616 0.220719 7.09147 0.640312 7.86784L5.04169 15.8281C5.10028 15.9342 5.21194 16 5.33334 16C5.45475 16 5.56641 15.9342 5.625 15.8281L10.028 7.86522C10.446 7.09147 10.6667 6.21613 10.6667 5.33331C10.6667 2.39259 8.27409 0 5.33334 0ZM5.33334 8C3.86297 8 2.66669 6.80372 2.66669 5.33334C2.66669 3.86297 3.86297 2.66669 5.33334 2.66669C6.80372 2.66669 8 3.86297 8 5.33334C8 6.80372 6.80372 8 5.33334 8Z"/>
                                    </svg>
                                    {$ubeeo_city}
                                </span>
                                    {/if}
									<span class="shop">
                                    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                        <path d="M15.7995 7.81271C16.0896 7.49372 16.0616 7.00481 15.737 6.72098L8.58641 0.464157C8.26184 0.180325 7.74149 0.186271 7.42375 0.477561L0.248845 7.05457C-0.0688874 7.34586 -0.084482 7.83414 0.214318 8.14473L0.394203 8.33207C0.692638 8.64266 1.17503 8.67969 1.47096 8.41453L2.00717 7.93433V14.9645C2.00717 15.3958 2.35667 15.745 2.78768 15.745H5.58448C6.0155 15.745 6.36499 15.3958 6.36499 14.9645V10.0462H9.93234V14.9645C9.92613 15.3955 10.2345 15.7447 10.6655 15.7447H13.6294C14.0605 15.7447 14.41 15.3955 14.41 14.9642V8.03332C14.41 8.03332 14.5581 8.16309 14.7408 8.32368C14.9232 8.48395 15.3063 8.35544 15.5963 8.03614L15.7995 7.81271Z"/>
                                    </svg>
                                    {$ubeeo_organisationNameExternal}
                                </span>
									<span class="hours">
                                    <svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                        <path d="M8.33325 0C3.92188 0 0.333252 3.58862 0.333252 8C0.333252 12.4114 3.92188 16 8.33325 16C12.7446 16 16.3333 12.4114 16.3333 8C16.3333 3.58862 12.7446 0 8.33325 0ZM12.1379 12.1379C12.0079 12.2679 11.8373 12.3334 11.6666 12.3334C11.496 12.3334 11.3252 12.2679 11.1953 12.1379L7.86194 8.80469C7.73657 8.68005 7.66663 8.51062 7.66663 8.33337V4C7.66663 3.63135 7.96521 3.33337 8.33325 3.33337C8.70129 3.33337 8.99988 3.63135 8.99988 4V8.05737L12.1379 11.1953C12.3986 11.4561 12.3986 11.8773 12.1379 12.1379Z"/>
                                    </svg>
                                    {$ubeeo_employment}
                                </span>
								</div>
							</div>
						</a>
					</article>',
'includeTVs'=>'ubeeo_vakgebied,ubeeo_employment,ubeeo_organisationNameExternal,ubeeo_city,ubeeo_maximum_hours,ubeeo_minimum_hours,ubeeo_latitude,ubeeo_longitude',
'filter_delimeter'=>'--',
'cache'=>0,
'tplFilter.outer.hours' =>'@INLINE {var $key = $table ~ $delimeter ~ $filter}
<div class="filter-group">
	<button class="js-filter open">
        {$filter | lexicon}
		<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
			<path d="M7.05666 0L4 3.05666L0.943344 0L0 0.943313L4 4.94331L8 0.943313L7.05666 0Z"/>
		</svg>
	</button>
		<span id="mse2_{$key}">
			<div class="mse2_number_inputs row">
				{$rows}
			</div>
		</span>
</div>
',

'tplFilter.row.hours' => '@INLINE {var $key = $table ~ $delimeter ~ $filter}
<span for="mse2_{$key}_{$idx}" class="d-flex align-items-center">
	{$title | lexicon}
	<input type="text" name="{$filter_key}" id="mse2_{$key}_{$idx}" value="{$value}" data-current-value="{$current_value}" class="form-control ml-1"/>
</span>',
'tplFilter.outer.range--locatie' =>'@INLINE {var $key = $table ~ $delimeter ~ $filter}
<div class="filter-group">
	<button class="js-filter open">
        {$filter | lexicon}
		<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
			<path d="M7.05666 0L4 3.05666L0.943344 0L0 0.943313L4 4.94331L8 0.943313L7.05666 0Z"/>
		</svg>
	</button>
		<span id="mse2_{$key}">
			<div class="mse2_number_inputs row">
				{$rows}
			</div>
		</span>
</div>
',
'tplFilter.row.range--locatie' => '@INLINE {var $key = $table ~ $delimeter ~ $filter}
<span for="mse2_{$key}_{$idx}" class="d-flex align-items-center">
	{$title | lexicon}
	<input type="text" name="{$filter_key}" id="mse2_{$key}_{$idx}" value="{$value}" data-current-value="{$current_value}" class="form-control ml-1"/>
</span>',

'filters'=>'tv--ubeeo_employment:string,tv--ubeeo_vakgebied:string,tv--ubeeo_maximum_hours:number,range--locatie:range',
'aliases'=>'tv--ubeeo_vakgebied==vakgebied,tv--ubeeo_employment==dienstverband,tv--ubeeo_maximum_hours==hours',
'toPlaceholders'=>'mf2_',
'showLog'=>1,
'tplPageWrapper' => '@INLINE <ul class="pagination">{$prev}{$pages}{$next}</ul>',
'tplPageActive' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">{$pageNo}</a></li>',
'tplPage' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">{$pageNo}</a></li>',
'tplPagePrev' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">«</a></li>',
'tplPageNext' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">»</a></li>',
'tplPagePrevEmpty' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">«</a></li>',
'tplPageNextEmpty' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">»</a></li>'
])}