<?php
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
session_start();
ob_start();
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') {
    die();
}
require('../../backend/functions.php');
session_write_close();
$settings = get_settings();
if (isset($_GET['lat']) && isset($_GET['lon'])) {
    $lat = $_GET['lat'];
    $lon = $_GET['lon'];
    $apiKey = $settings['google_api_key'];
    $url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lon&key=$apiKey";
    $response = file_get_contents($url);
    ob_end_clean();
    header('Content-Type: application/json');
    echo $response;
} else {
    ob_end_clean();
    echo json_encode(['status' => 'error', 'message' => 'Missing parameters']);
}