. * * @link https://www.librenms.org * * @copyright 2018 Tony Murray * @author Tony Murray */ namespace App\ApiClients; use LibreNMS\Interfaces\Geocoder; class NominatimApi extends BaseApi implements Geocoder { use GeocodingHelper; protected string $base_uri = 'https://nominatim.openstreetmap.org'; protected string $geocoding_uri = '/search'; /** * Get latitude and longitude from geocode response */ protected function parseLatLng(array $data): array { return [ 'lat' => isset($data[0]['lat']) ? $data[0]['lat'] : 0, 'lng' => isset($data[0]['lon']) ? $data[0]['lon'] : 0, ]; } /** * Build request option array * * @throws \Exception you may throw an Exception if validation fails */ protected function buildGeocodingOptions(string $address): array { return [ 'query' => [ 'q' => $address, 'format' => 'json', 'limit' => 1, ], 'headers' => [ 'User-Agent' => 'LibreNMS', 'Accept' => 'application/json', ], ]; } }