. * * @package LibreNMS * @link http://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 $base_uri = 'http://nominatim.openstreetmap.org'; protected $geocoding_uri = '/search'; /** * Get latitude and longitude from geocode response * * @param array $data * @return array */ protected function parseLatLng($data) { return [ 'lat' => isset($data[0]['lat']) ? $data[0]['lat'] : 0, 'lng' => isset($data[0]['lon']) ? $data[0]['lon'] : 0, ]; } /** * Build Guzzle request option array * * @param string $address * @return array * @throws \Exception you may throw an Exception if validation fails */ protected function buildGeocodingOptions($address) { return [ 'query' => [ 'q' => $address, 'format' => 'json', 'limit' => 1, ], 'headers' => [ 'User-Agent' => 'LibreNMS', 'Accept' => 'application/json', ] ]; } }