-
Notifications
You must be signed in to change notification settings - Fork 198
Adding Google Maps JavaScript API #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dannyaudi
wants to merge
2
commits into
learning-software-engineering:main
Choose a base branch
from
dannyaudi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
## Tech Stacks | ||
|
||
### [Learning MySQL for databases](./Tech_Stacks/Learning_MySQL.md) | ||
### [Google Maps JavaScript API](./Tech_Stacks/Google_Maps_API.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Google Maps Javascript API | ||
|
||
## Table of contents | ||
### [Introduction](#introduction-1) | ||
### [Requirements](#requirements-1) | ||
### [Basic Google Map Integration](#basic-google-map-integration-1) | ||
### [Embedding a Google Map on a React Website](#embedding-a-google-map-on-a-react-website-1) | ||
### [Common Issues](#common-issues-1) | ||
|
||
## Introduction | ||
|
||
The following is a simple introduction to utilizing Google Maps Javascript API to embed custom maps on a website. This article assumes some basic knowledge of HTML, CSS, JavaScript, and Node.js | ||
|
||
|
||
## Requirements | ||
|
||
To use this API, the user should have Node.js installed and configured correctly. Additionally, users need to sign up for a Google Developer account, and set up their Google Maps Javascript API key, by adding a payment method to their account and following this guide. | ||
|
||
https://developers.google.com/maps/documentation/embed/get-api-key | ||
|
||
In their project, users must make sure to load the Google API script correctly, by specifying their unique Google Map API Key or else their map will not load correctly. For example, | ||
|
||
`src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"` | ||
|
||
In this example, `AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg` is the unique key id. | ||
|
||
|
||
## Basic Google Map Integration | ||
|
||
Google has an introductory guide on their developers website that details the process to integrate a simple Google Map with custom markers on a website. | ||
|
||
https://developers.google.com/maps/documentation/javascript/adding-a-google-map#maps_add_map-javascript | ||
|
||
Note that this guide DOES NOT work for a React website, users working in a react environment must follow the "Embedding a Google Map on a React Website" section. | ||
|
||
Users must make sure to edit the `<script>` tag that loads the Google Map API to add their unique API key. | ||
|
||
|
||
## Embedding a Google Map on a React Website | ||
|
||
Embedding a Google Map on a React website is different as it requires importing a different package and following a different guide. The guide can be found here: | ||
|
||
https://www.npmjs.com/package/@react-google-maps/api | ||
|
||
A full documentation of the React Google Maps API package can be found here: | ||
|
||
https://react-google-maps-api-docs.netlify.app | ||
|
||
Users utilizing this package must make sure to run `npm install @react-google-maps/api` or add the package to their dependencies before running the website. | ||
|
||
The individual compenents that the user wishes to use must also be included in the imports at the beginning of whichever files they are used in. A full list of the package components and their properties can be found in the "react-google-maps-api-docs" guide link of this section. For example, a user creating a custom map and adding markers to it would perform the following at the beginning of their JavaScript file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a link for the "react-google-maps-api-docs". You can use |
||
|
||
`import { GoogleMap, Marker} from '@react-google-maps/api';` | ||
|
||
|
||
## Common Issues | ||
|
||
Here a few common issues that may arise when working with the Google Maps API and their likely solutions. | ||
|
||
1. The package components are not being imported correctly<br /> | ||
Ensure that you are importing the Google Maps API script correctly in your HTML file with your unique key, or running `npm install @react-google-maps/api` if you are working within a React project. | ||
2. The package is loading, but the map is not displaying <br /> | ||
Make sure you are dedicating a specific `<div>` to the map section and attaching it there. | ||
3. The map only displays sometimes <br /> | ||
Add `async` and `defer` to your script tag in your HTML file, as your API script may not be loading before your JavaScript files are run. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider linking "Embedding a Google Map on a React Website" to its corresponding section.