token = $token; $this->baseUrl = rtrim($baseUrl, '/'); $this->headers = [ 'Authorization: Bearer ' . $this->token, 'Content-Type: application/json', 'Accept: application/json', ]; } // ── Geocoding ── /** * Convert address to coordinates */ public function geocodeAddress(array $query = []): array { return $this->request('GET', '/geocode', $query); } /** * Convert coordinates to address */ public function reverseGeocode(array $query = []): array { return $this->request('GET', '/reverse', $query); } // ── HTTP helpers ── private function request(string $method, string $path, array $query = [], array $body = []): array { $url = $this->baseUrl . $path; if (!empty($query)) { $url .= '?' . http_build_query($query); } $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $this->headers, CURLOPT_TIMEOUT => 30, ]); if (!empty($body) && in_array($method, ['POST', 'PUT', 'PATCH'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); } $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ['status' => $status, 'data' => json_decode($response, true)]; } }