Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Automobiles (12)
    • Cars (7)
  • Blog (103)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (51)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

JavaScriptOthers

Use Multiple Google Maps in same webpage

By Admin
April 4, 2020 2 Min Read
0

In this article, we will be learning to use multiple Google Maps in a single webpage. We will be taking the help of Google Maps JavaScript API in order to load multiple instances of google maps in our page.

HTML

For displaying multiple maps, you need multiple container for map. Just remember to specify height and width of the container. Here’s the sample HTML.

<div id="block-wrp">
  <div class="block-item">
    <div id="mapCanvas1" class="map-item"> </div>
    <span class="city-name">Label 1</span> 
  </div>
    
  <div class="block-item">
    <div id="mapCanvas2" class="map-item"> </div>
    <span class="city-name">Label 2</span> 
  </div>
</div>

JavaScript

In order to use the Google Maps JavaScript API, we need Google API key. If you don’t have one, refer Add multiple custom markers with legend in Google Map.

We can include maps API to our webpage simply by adding the following line.

<script async defer src="https://maps.google.com/maps/api/js?key=API_KEY&callback=drawMap"></script>

where API_KEY is the Google API key and drawMap is the callback function which is called once this API is loaded.

The callback function drawMap will look like this :

<script type="text/javascript">
  var map1, map2;
  
  function drawMap() {
  
    var mapCenter = new google.maps.LatLng(-33.865143, 151.209900); // Sydney
    
    var mapOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: true,
      center: mapCenter,
      fullscreenControl: false 
    }
    
    // Generate First Map
    map1 = new google.maps.Map(document.getElementById("mapCanvas1"), mapOptions);
    
    // Generate Second Map
    map2 = new google.maps.Map(document.getElementById("mapCanvas2"), mapOptions);
  
  }
</script>

 

Complete Code

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Use Multiple Google Maps in same webpage</title>
<style>
#block-wrp {
  width: 784px;
  display: flex;
  display: -webkit-flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
#block-wrp .block-item {
  height: 400px;
  width: 48%;
  position: relative;
  display: flex;
  display: -webkit-flex;
  flex-direction: column;
  -webkit-flex-direction: column
}
#block-wrp .block-item .map-item {
  height: 90%
}
#block-wrp .block-item span.city-name {
  text-align: center;
  color: #000;
  text-transform: uppercase;
  font-weight: bold;
  background: #a2ccff;
  height: 10%;
  line-height: 2em;
}
</style>
</head>
<body>

  <h1>Use Multiple Google Maps in same webpage</h1>
<div id="block-wrp">
  <div class="block-item">
    <div id="mapCanvas1" class="map-item"> </div>
    <span class="city-name">London</span> </div>
  <div class="block-item">
    <div id="mapCanvas2" class="map-item"> </div>
    <span class="city-name">Amsterdam</span> </div>
</div>
<script type="text/javascript">
var map1, map2;
function drawMap() {
    
    var mapOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: true,
      fullscreenControl: false 
     }
    mapOptions.center = new google.maps.LatLng(51.509865, -0.118092); // London
    map1 = new google.maps.Map(document.getElementById("mapCanvas1"), mapOptions);
    
    mapOptions.center = new google.maps.LatLng(52.370216, 4.895168); // Amsterdam
    map2 = new google.maps.Map(document.getElementById("mapCanvas2"), mapOptions);
 }
</script> 
<script async defer src="https://maps.google.com/maps/api/js?key=AIzaSyCvDN-LuS_9_VFkR71Sc56P6y4cwWKvEpU&callback=drawMap"></script>
</body>
</html>

Follow this video for complete guidance :

Tags:

google mapsmaps
Author

Admin

Follow Me
Other Articles
Previous

Simple Responsive YouTube Video Embeds

Next

Install Laravel on Ubuntu with 4 simple steps

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide
  • Chiranjibi Adhikari Appointed Acting President of CAN Federation
  • How to Design a Student Marksheet Using HTML and CSS

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You Admin
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide Admin
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme