Skip to content

Commit d112554

Browse files
authored
Merge pull request #208 from gbanaag/main
updated markdown
2 parents 1b04cda + 5612773 commit d112554

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

projects/build-a-cafe-finder-with-javascript/build-a-cafe-finder-with-javascript.mdx

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919
cl="for-sidebar"
2020
/>
2121

22-
# Project Title
22+
# Build a Cafe Finder with JavaScript and the Google Maps Platform
2323

2424
<AuthorAvatar
2525
author_name="Gabriela Banaag"
@@ -38,47 +38,47 @@ tags:
3838

3939
**Read Time:** 30 minutes
4040

41-
# ## Introduction
41+
## # Introduction
4242

4343
If you’re an iced-bev-meets-coworking-space fiend like me and want to shake up what cafe you head to next, this is the perfect project for you. We’ll be using our trilogy of web dev tools: ****HTML****, ****CSS****, and ****JavaScript****, and an API from the Google Maps Platform called ****Places****. We’ll also make some quick animations and implement swiping recognition with a JavaScript library called ****Hammer****!
4444

45-
## About the Google Maps Platform
45+
## # About the Google Maps Platform
4646

4747
The Google Maps Platform is a collection of Application Programming Interfaces (APIs) and Software Development Kits (SDKs). Each tool on the platform lets users use Google Maps functions and data in their own projects!
4848

4949
Some popular apps that use the Google Maps Platform include Uber and Airbnb, which access a user’s location to calculate rides and show rentals in specific areas!
5050

5151
<ImageZoom src="https://miro.medium.com/v2/resize:fit:7680/1*ThzU2nLvoAHfPwLqlddwhQ.png" />
5252

53-
The [Places API](https://developers.google.com/maps/documentation/places/web-service/overview) is a smaller API under the Google Maps API. It fetches location data like location names, addresses, photos, and many more attributes! It’s a great tool for accessing updated data and finding multiple places without manually copying all of their information into a project. ****We’ll be using this in our project! ****
53+
The [Places API](https://developers.google.com/maps/documentation/places/web-service/overview) is a smaller API under the Google Maps API. It fetches location data like location names, addresses, photos, and many more attributes! It’s a great tool for accessing updated data and finding multiple places without manually copying all of their information into a project. ****We’ll be using this in our project!****
5454

55-
# ## Setup
55+
## # Setup
5656

57-
## ### Workspace
57+
#### # Workspace
5858

59-
Start by creating a new HTML/CSS/JS project in [[Codédex Builds](https://www.codedex.io/builds)](https://www.codedex.io/builds). You can also use a Code editor of your choice, like [VSCode](https://code.visualstudio.com/).
59+
Start by creating a new HTML/CSS/JS project in [Codédex Builds](https://www.codedex.io/builds). You can also use a Code editor of your choice, like [VSCode](https://code.visualstudio.com/).
6060

61-
## ### Google Cloud Console
61+
#### # Google Cloud Console
6262

63-
Set up your project in the [[Google Cloud Console](https://developers.google.com/maps/documentation/elevation/cloud-setup)](https://developers.google.com/maps/documentation/elevation/cloud-setup). You’ll enter a project name and billing information. Your website won’t work as it should unless you enable billing, but you won’t be charged if the API doesn’t get called past the monthly limit (we'll teach you how to cap it at the limit, which is usually 10,000 API calls).
63+
Set up your project in the [[Google Cloud Console](https://developers.google.com/maps/documentation/elevation/cloud-setup). You’ll enter a project name and billing information. Your website won’t work as it should unless you enable billing, but you won’t be charged if the API doesn’t get called past the monthly limit (we'll teach you how to cap it at the limit, which is usually 10,000 API calls).
6464

65-
## ### Clone Template
65+
#### # Clone Template
6666

67-
Head over to [[this GitHub link](https://github.com/gbanaag/codedex-cafe-finder-template/tree/main)](https://github.com/gbanaag/codedex-cafe-finder-template/tree/main) and clone the repository. The repo has all the basic HTML and CSS set up so we don’t have to worry about it later and focus on API implementation.
67+
Head over to [this GitHub link](https://github.com/gbanaag/codedex-cafe-finder-template/tree/main) and clone the repository. The repo has all the basic HTML and CSS set up so we don’t have to worry about it later and focus on API implementation.
6868

6969
You can clone the template in 3 different ways:
7070

7171
- Downloading the folder and adding it to your local workspace
7272
- GitHub Desktop app
7373
- ``git clone`` with command line
7474

75-
If you don’t have VS Code and don’t know how to use it, head over to our [[VS Code setup tutorial](https://www.codedex.io/projects/set-up-your-local-environment-in-python#download-vs-code)](https://www.codedex.io/projects/set-up-your-local-environment-in-python#download-vs-code).
75+
If you don’t have VS Code and don’t know how to use it, head over to our [VS Code setup tutorial](https://www.codedex.io/projects/set-up-your-local-environment-in-python#download-vs-code).
7676

77-
# ## Accessing Locations with JavaScript
77+
## # Accessing Locations with JavaScript
7878

7979
Time to write some back-end code!
8080

81-
## ### API Key
81+
#### # API Key
8282

8383
Here’s how to create and protect your API key:
8484

@@ -104,7 +104,7 @@ const apiKey = "STRING_OF_RANDOM_CHARACTERS_HERE";
104104

105105
</aside>
106106

107-
## ### cors-anywhere
107+
#### # cors-anywhere
108108

109109
Head to [https://cors-anywhere.herokuapp.com/](https://cors-anywhere.herokuapp.com/). Make sure to click on the ``Request temporary access to the demo server`` button to get set up with a temporary server for your project.
110110

@@ -115,7 +115,7 @@ const useProxy = true;
115115
const proxy = "https://cors-anywhere.herokuapp.com/";
116116
```
117117

118-
## ### Geolocation
118+
#### # Geolocation
119119

120120
To see cafes nearby, the browser needs access to your location. There’s a built-in JavaScript function that takes care of that for you called ``useLocation()`` and it takes your device’s latitude and longitude coordinates.
121121

@@ -133,7 +133,7 @@ if (cache.timestamp && now - cache.timestamp < 10 * 60 * 1000) {
133133
}
134134
```
135135
136-
If there’s no cached location information found, the browser pulls your current latitude and longitude from a built in function.
136+
If there’s no cached location information found, the browser pulls your current latitude and longitude from a built-in function.
137137
138138
```jsx
139139
else {
@@ -152,7 +152,7 @@ We’ll save the location and timestamp in ``localStorage`` in case we use our c
152152
}
153153
```
154154

155-
## ### Using the API
155+
#### # Using the API
156156

157157
We’ll start implementing the Google Places API to take locations and their information from Google Maps itself! We’ll start by writing the `useLocation()` function.
158158

@@ -187,7 +187,7 @@ If the API finds results for nearby cafes, we’ll take that data and insert it
187187
}
188188
```
189189

190-
# ## Cafe UI and Animations
190+
## # Cafe UI and Animations
191191

192192
We’re gonna create a wrapper for our cards, and inject data from the API into the wrapper as we go. To start, let’s make a function called ``displayCards()`` that renders a div container whenever the website starts up.
193193

@@ -241,7 +241,7 @@ const cafeData = {
241241
};
242242
```
243243
244-
Putting in tags between the ``` symbol when changing an element’s ``innerHTML`` allows you to render HTML elements when functions run. We’ll append (connect) the card to its wrapper, and append its wrapper to its container.
244+
Putting in tags between the ````` symbol when changing an element’s ``innerHTML`` allows you to render HTML elements when functions run. We’ll append (connect) the card to its wrapper, and append its wrapper to its container.
245245

246246
```jsx
247247
card.innerHTML = `
@@ -255,14 +255,14 @@ wrapper.appendChild(card);
255255
container.appendChild(wrapper);
256256
```
257257

258-
## ### Hammer
258+
#### # Hammer
259259

260260
[Hammer](http://hammerjs.github.io/) is a library used to recognize touch gestures in the browser!
261261

262262
<aside>
263263
💡
264264

265-
A ****library**** is a collection of reusable resources like functions, classes, and pieces of pre-written code. An **API****** is an interface that lets your code communicate with another application.
265+
A ****library**** is a collection of reusable resources like functions, classes, and pieces of pre-written code. An **API** is an interface that lets your code communicate with another application.
266266

267267
</aside>
268268

@@ -272,8 +272,6 @@ To make sure we have swiping gestures detected on the site, we’re gonna import
272272
<script src="https://cdn.jsdelivr.net/npm/[email protected]/hammer.min.js"></script>
273273
```
274274

275-
[gif]
276-
277275
We’re going to add a function that detects left and right swipes and makes each cafe card flick and fade away. Add this to the bottom of your `displayCards()` function to make it happen:
278276

279277
```jsx
@@ -291,11 +289,11 @@ We’re going to add a function that detects left and right swipes and makes eac
291289
});
292290
```
293291
294-
## ### Saving Cafes
292+
#### # Saving Cafes
295293
296-
We’ll be using ``localStorage`**`** to save cafes to the browser. It automatically caches (saves) specific interactions from your site to your browser that you choose to save without needing a database.
294+
We’ll be using ``localStorage`` to save cafes to the browser. It automatically caches (saves) specific interactions from your site to your browser that you choose to save without needing a database.
297295
298-
** **JSON Parsing**** is used to take strings and save them as data structures like objects or arrays. To implement this, we'll add a line that stores the string as a cafe **object.** Then we'll save the cafe object into an array called ``saved``.
296+
**JSON Parsing** is used to take strings and save them as data structures like objects or arrays. To implement this, we'll add a line that stores the string as a cafe **object.** Then we'll save the cafe object into an array called ``saved``.
299297
300298
```jsx
301299
function saveCafe(cafeJSON) {
@@ -372,7 +370,7 @@ container.appendChild(card);
372370
}
373371
```
374372
375-
# ## Conclusion
373+
## # Conclusion
376374
377375
Here's my final result:
378376
@@ -386,7 +384,7 @@ If you’re looking for another challenge or a way to spice up your project, you
386384
- Adding a map of places next to the cards
387385
- Animating your cards further
388386
389-
## ### Troubleshooting
387+
#### # Troubleshooting
390388
391389
- Make sure you’re granted temporary access on https://cors-anywhere.herokuapp.com/.
392390
- Make sure to allow location access when you try out the site.

0 commit comments

Comments
 (0)