function calculateDistance($address1, $address2) {
    $apiKey = "AIzaSyDa_d1tGwiwmST9lBBWRwWSdGiuECKiE4s";
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=" . urlencode($address1) . "&destinations=" . urlencode($address2) . "&key=" . $apiKey;

    $response = file_get_contents($url);
    if ($response === false) {
        return 'Error: Unable to fetch distance data from the API.';
    }

    $data = json_decode($response, true);
    if ($data === null || $data['status'] !== 'OK') {
        if ($data !== null && isset($data['error_message'])) {
            return 'Error: ' . $data['error_message'];
        } else {
            return 'Error: An unknown error occurred.';
        }
    }

    $distance = $data['rows'][0]['elements'][0]['distance']['text'];
    return $distance;
}


$distance = calculateDistance("Stockholm, Sweden", "Köping, Sweden");
echo "Distance: " . $distance;
