enhanced preorder map

This commit is contained in:
2025-09-18 12:55:26 +02:00
parent b69bfc3afe
commit f05ff28394
4 changed files with 384 additions and 57 deletions

View File

@@ -0,0 +1,48 @@
<?php
class GeocodingController extends mfBaseController {
protected function init() {
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
}
protected function autocompleteAction() {
$search = urlencode($this->request->q);
$url = TT_GEOCODING_API_URL . "?address={$search}&key=" . TT_GEOCODING_API_SECRET . "&region=at&language=de&components=country:AT";
if (!$response = @file_get_contents($url)) {
self::returnJson([]);
return;
}
$data = json_decode($response, true);
var_dump($data); // Debugging line, can be removed in production
if ($data['status'] !== 'OK' || empty($data['results'])) {
self::returnJson([]);
return;
}
$out = [];
foreach ($data['results'] as $entry) {
$hasHouseNumber = false;
foreach ($entry['address_components'] as $component) {
if (in_array('street_number', $component['types'])) {
$hasHouseNumber = true;
break;
}
}
$text = $entry['formatted_address'];
$value = "{$entry['geometry']['location']['lat']},{$entry['geometry']['location']['lng']}" . ($hasHouseNumber ? '' : ', area');
$out[$text] = ['value' => $value, 'text' => $text];
}
self::returnJson(array_values($out));
}
}