enhanced preorder map
This commit is contained in:
48
application/Geocoding/GeocodingController.php
Normal file
48
application/Geocoding/GeocodingController.php
Normal 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 . "®ion=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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user