Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions complex-api-1/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* General Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: "Arial", sans-serif;
background-color: #f9f9f9;
color: #333;
}

header {
background-color: #ff6347;
color: white;
padding: 10px 20px;
border-bottom: 2px solid #d3d3d3;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

nav {
display: flex;
justify-content: space-between;
align-items: center;
}

nav .logo {
font-size: 24px;
font-weight: bold;
}

nav ul {
display: flex;
list-style: none;
}

nav li {
margin: 0 15px;
font-size: 18px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
color: white;
transition: color 0.3s ease;
}

nav li:hover {
color: #ffd700;
}

main {
text-align: center;
padding: 40px 20px;
}

main h1 {
font-size: 28px;
margin-bottom: 20px;
color: #2e2e2e;
}

label {
display: block;
font-weight: bold;
margin: 10px 0;
}

input[type="text"] {
width: 20%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}

button {
background-color: #ff6347;
color: white;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #cc5141;
}

ul {
list-style-type: disc;
margin: 20px auto;
padding: 0;
width: 80%;
text-align: left;
}
39 changes: 39 additions & 0 deletions complex-api-1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="This is where your description goes">
<meta name="keywords" content="one, two, three">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Complex API #1</title>

<!-- external CSS link -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<header>
<nav>
<div class="logo">
<i class="fas fa-utensils"></i> Restaurant Finder
</div>
<ul>
<li><i class="fas fa-home"></i> Home</li>
<li><i class="fas fa-info-circle"></i> About</li>
<li><i class="fas fa-envelope"></i> Contact</li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Search for restaurants in your city!</h1>
<label for="location">Enter a city and country:</label>
<input type="text" id="city" placeholder="e.g., Boston, Dubai, Santo Domingo" required>
<input type="text" id="country" placeholder="e.g., England, United States, Dominican Republic" required>
<button type="button" name="button">Find restaurants</button>
<ul id="restaurantUl"></ul>
</section>
</main>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions complex-api-1/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
document.querySelector('button').addEventListener('click', getCoordinates);

function getCoordinates() {
const cityName = document.getElementById('city').value
const countryName = document.getElementById('country').value

const geoApiKey = '0tHj+S4vc1MB63o6bQVHRw==e2NEFPOhTwG3Em9S'; // Replace with your actual API key
const geoUrl = `https://api.api-ninjas.com/v1/geocoding?city=${cityName}&country=${countryName}`

fetch(geoUrl, {
headers: {
"X-Api-Key": geoApiKey // Include the API key in the Authorization header inside the fetch parameter
}
})
.then(res => res.json())
.then(data => {
console.log(data)
const latitude = data[0].latitude
const longitude = data[0].longitude
getRestaurants(latitude, longitude)
})
.catch(err =>{
console.log(`error ${err}`)
});


}

function getRestaurants(latitude, longitude) {
const geoApifyKey = '53800e6a1a134ddc9511446d79c1f039'; // GeoApify API key
const category = 'catering.restaurants';
const radius = 5000;

const geoApifyUrl = `https://api.geoapify.com/v2/places?categories=catering&filter=circle:${longitude},${latitude},${radius}&apiKey=${geoApifyKey}`;


fetch(geoApifyUrl)
.then(response => response.json())
.then(response => {
console.log(response);

const restaurantList = document.querySelector('#restaurantUl');
restaurantList.innerHTML = ''; // Clear previous results

response.features.forEach(restaurant => { //features is the name of the restaurants array
const listItem = document.createElement('li');

const name = restaurant.properties.name
const address = restaurant.properties.address_line2
const contact = restaurant.properties.contact.phone

listItem.innerHTML = `<strong>Name:</strong> ${name} <strong>Address:</strong> ${address} <strong>Contact:</strong> ${contact} `;

restaurantList.appendChild(listItem);
})
})
.catch(err =>{
console.log(`error ${err}`)
});


}