How to create a simple map using jQuery ?
Last Updated :
06 Jul, 2023
jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript.
What are Google Maps?
Google Map is a free web-based mapping service application and technology provided by Google. The application provides comprehensive information about geographical regions, street maps, and the route planner for traveling by car, foot, or public transportation Satellite views of the countries around the globe.
HTML Google Map can be used to display the maps on webpage. One can simply add a map HTML page.
Syntax:
<!DOCTYPE html>
<html>
<body>
<h1Map Example</h1>
<div id="map">Enter text</div>
</body>
Set the Map Size
Syntax:
<div id="map"
style="width:400px;height:400px;background:grey">
</div>
Create a function to set the map properties
The map properties can be set by creating a function. We have to use the functionalities of Google Maps API provided by a JavaScript library located at Google.
<script src=
"https://maps.googleapis.com/maps/api/js?callback=myMap">
</script>
Create A Map
- In the above example, we will use Google API to load google map.
<script src = "https://maps.googleapis.com/maps/api/js"></script>
- Following are the steps required to get an API key:
- To customize the maps:
let CustomOp = {
center: new google.maps.LatLng(28.502212, 77.405603),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
- In this case, CustomOp is an object that contains 3 options, centre, zoom, and maptypeid.
- centre: This property is used to set the specific point in maps.
- zoom: This property is used to specify the zoom level on a specific point.
- maptypeid: This property is used to specify the type of map. (ROADMAP, SATELLITE, HYBRID, TERRAIN)
To customize the Google map, there are four types of maps provided.
- ROADMAP: This type of map shows the street view of a specific area. It is the default type of map.
- SATELLITE: This type of map shows satellite images of a specific area.
- HYBRID: This type of map shows the major streets of the specific area.
- TERRAIN: This type of map shows the terrain and vegetation.
Example 1: ROADMAP
html
<!DOCTYPE html>
<html>
<head>
<title>
Google Maps | Types
</title>
<!-- Add Google map API source -->
<script src=
"https://maps.googleapis.com/maps/api/js">
</script>
<script>
function GFG() {
let CustomOp = {
center: new google.maps.LatLng(
28.502212, 77.405603),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Map object
let map = new google.maps.Map(
document.getElementById("DivID"),
CustomOp
);
}
</script>
</head>
<!-- Function that execute when page load -->
<body onload="GFG()">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<h3>Google Maps</h3>
<!-- Basic Container -->
<div id="DivID"
style="width:400px; height:300px;">
</div>
</center>
</body>
</html>
Output:
Example 2: SATELLITE
html
<!DOCTYPE html>
<html>
<head>
<title>
Google Maps | Types
</title>
<!-- Add Google map API source -->
<script src=
"https://maps.googleapis.com/maps/api/js">
</script>
<script>
function GFG() {
let CustomOp = {
center: new google.maps.LatLng(
28.502212, 77.405603),
zoom: 17,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
// Map object
let map = new google.maps.Map(
document.getElementById("DivID"),
CustomOp
);
}
</script>
</head>
<!-- Function that execute when page load -->
<body onload="GFG()">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<h3>Google Maps</h3>
<!-- Basic Container -->
<div id="DivID"
style="width:400px; height:300px;">
</div>
</center>
</body>
</html>
Output:
Example 3: HYBRID
html
<!DOCTYPE html>
<html>
<head>
<title>
Google Maps | Types
</title>
<!-- Add Google map API source -->
<script src=
"https://maps.googleapis.com/maps/api/js">
</script>
<script>
function GFG() {
let CustomOp = {
center: new google.maps.LatLng(
28.502212, 77.405603),
zoom: 17,
mapTypeId: google.maps.MapTypeId.HYBRID
};
// Map object
let map = new google.maps.Map(
document.getElementById("DivID"),
CustomOp
);
}
</script>
</head>
<!-- Function that execute when page load -->
<body onload="GFG()">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<h3>Google Maps</h3>
<!-- Basic Container -->
<div id="DivID"
style="width:400px; height:300px;">
</div>
</center>
</body>
</html>
Output:
Example 4: TERRAIN
html
<!DOCTYPE html>
<html>
<head>
<title>
Google Maps | Types
</title>
<!-- Add Google map API source -->
<script src=
"https://maps.googleapis.com/maps/api/js">
</script>
<script>
function GFG() {
let CustomOp = {
center: new google.maps.LatLng(
28.502212, 77.405603),
zoom: 17,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
// Map object
let map = new google.maps.Map(
document.getElementById("DivID"),
CustomOp
);
}
</script>
</head>
<!-- Function that execute when page load -->
<body onload="GFG()">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<h3>Google Maps</h3>
<!-- Basic Container -->
<div id="DivID"
style="width:400px; height:300px;">
</div>
</center>
</body>
</html>
Output:

Similar Reads
JavaScript Tutorial
JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. JavaScript is an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side : On client sid
11 min read
Web Development
Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers
React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
HTML Tutorial
HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
10 min read
JavaScript Interview Questions and Answers
JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as
15+ min read
React Tutorial
React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon
8 min read
HTML Interview Questions and Answers
HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
NodeJS Interview Questions and Answers
NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net
15+ min read
What is an API (Application Programming Interface)
In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of
10 min read
Introduction of Firewall in Computer Network
A firewall is a network security device either hardware or software-based which monitors all incoming and outgoing traffic and based on a defined set of security rules it accepts, rejects, or drops that specific traffic. It acts like a security guard that helps keep your digital world safe from unwa
10 min read