schneespur/app/Services/GeocodingService.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +00:00

43 lines
1.2 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
class GeocodingService
{
public function resolve(string $street, string $zip, string $city): ?array
{
try {
$response = Http::withHeaders([
'User-Agent' => brand_slug().'/1.0 ('.config('app.url').')',
])
->timeout(5)
->get('https://nominatim.openstreetmap.org/search', [
'street' => $street,
'city' => $city,
'postalcode' => $zip,
'country' => 'de',
'format' => 'json',
'limit' => 1,
]);
if ($response->successful()) {
$data = $response->json();
if (! empty($data) && isset($data[0]['lat'], $data[0]['lon'])) {
return [
'lat' => (float) $data[0]['lat'],
'lon' => (float) $data[0]['lon'],
];
}
}
return null;
} catch (ConnectionException|RequestException $e) {
return null;
}
}
}