'NO_RESULTS']; } if (($data['status'] ?? '') !== 'OK') { throw new RuntimeException('UNEXPECTED_STATUS'); } if (empty($data['results'])) { return ['status' => 'NO_RESULTS']; } $first = $data['results'][0]; $location = $first['geometry']['location']; return ['status' => 'OK', 'lat' => $location['lat'], 'lng' => $location['lng'], 'address' => $first['formatted_address']]; } function migrate(ApiClient $client): array { $adapter = new GoogleGeocodeAdapter($client); $text = $adapter->geocode(['address' => 'Domaniewska 37, Warszawa']); $components = $adapter->geocode([ 'components' => 'locality:Warszawa|route:Domaniewska|street_number:37|country:PL', ]); $nativeInput = $client->geocoder()->geocode( city: 'Warszawa', street: 'Domaniewska', house: '37', country: 'PL', extra: ['format' => 'google'], )->data(); return array_map('readLocation', [$text, $components, $nativeInput]); } if (realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) { try { $client = buildClient(getenv('AUTOMAPA_SESSION_ID') ?: ''); echo json_encode(migrate($client)); } catch (AutomapaException | RuntimeException | InvalidArgumentException $error) { fwrite(STDERR, "SDK_ERROR_OR_SESSION_REQUIRED\n"); exit(1); } }