<?php
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
ob_start();
session_start();
if($_SESSION['sml_si']!=session_id()) {
    die();
}
require('../functions.php');
$settings = get_settings();
if (isset($_GET['query'])) {
    $query = urlencode($_GET['query']);
    $apiKey = $settings['google_api_key'];
    $url = "https://maps.googleapis.com/maps/api/geocode/json?address={$query}&key={$apiKey}";
    $response = file_get_contents($url);
    if ($response !== false) {
        ob_end_clean();
        header('Content-Type: application/json');
        echo $response;
    } else {
        ob_end_clean();
        http_response_code(500);
        echo json_encode(['error' => 'Failed to contact Google Geocoding API']);
    }
} else {
    ob_end_clean();
    http_response_code(400);
    echo json_encode(['error' => 'Missing address query']);
}