Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:34:54+00:00 2026-06-09T08:34:54+00:00

In my web application, I am using Google Maps JavaScript API v3. In a

  • 0

In my web application, I am using Google Maps JavaScript API v3. In a web page I am creating a google map using following code:

 var centerLatLng = new google.maps.LatLng(obj.centerlat, obj.centerlong);
 var myOptions = {
     center: centerLatLng,
     zoom: 17,
     mapTypeId: google.maps.MapTypeId.ROADMAP,
     draggable: true
 };

 var map = new google.maps.Map(document.getElementById("map_convas"), myOptions);

 var markerArray = obj.locations;
 var triangleCoords = new Array();

 for(var x=0;x<markerArray.length;x++){
      triangleCoords.push(new google.maps.LatLng(markerArray[x].latitude, markerArray[x].longitude));
 }

 var polypath = new google.maps.Polyline({
       path: triangleCoords,
       strokeColor: "#FF0000",
       strokeOpacity: 1.0,
       strokeWeight: 2
 });

 polypath.setMap(map);

This code shows map correctly. Then I have a button under that map. When I click on that button another google javascript map should be displayed in a div called map_convas_1, which is in the same page. Code for this I wrote is following:

 $('#secondmapbtn').unbind("click");
 $('#secondmapbtn').bind('click', function(){ 


      var centerLatLng2 = new google.maps.LatLng(secondcenterlat, secondcenterlong);
 var myOptions2 = {
     center: centerLatLng2,
     zoom: 17,
     mapTypeId: google.maps.MapTypeId.ROADMAP,
     draggable: true
 };
   $('#map_convas_2').show();
 var map2 = new google.maps.Map(document.getElementById("map_convas_2"), myOptions2);

 var secondMarkerArray = secondobj.locations;

 // putting markers in map 

     for(var i=0;i<markerArray.length;i++){
      var myLatlng = new google.maps.LatLng(secondMarkerArray[i].latitude, secondMarkerArray[i].longitude);

      var marker = new google.maps.Marker({
           clickable: true,
           position: myLatlng,
           map: map2,
           zIndex: i
      });
      marker.setIcon('marker_icon.png');
}
 });

HTML for both divs are

 <div id='map_convas'></div>
 <div id='map_convas_2'></div>

and css is:

 #map_convas{
position: absolute;
    border-radius: 8px;
    width:657px; 
    height:592px;
    top: 50px;
    left: 100px;
 }

 #map_convas_2{
position: absolute;
    border-radius: 8px;
    width:657px; 
    height:592px;
    top: 700px;
    left: 100px;
    display:none;
 }

After clicking button, second map is shown but its not showing correctly. I am attaching screenshots that how first and second maps look like. If I comment the first map instance code then second map works fine. It means that problem comes when I create second map instance. Does anybody know that why second map is not OK and how to solve this problem?

First Map

Second Map

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:34:56+00:00Added an answer on June 9, 2026 at 8:34 am

    After this line

    var map2 = new google.maps.Map(document.getElementById("map_convas_2"), myOptions2);

    add

     google.maps.event.trigger(map2, 'resize');
    

     
    You may need to move that new line down the code a little, or set a Timeout. The issue is that the .show() is taking some time to reset the map size in the DOM, and the API is being told the map still has zero size when it sets it up. Consequently you only get the minimum number of tiles to show a zero-size map in the top-left corner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a web application using the Google Maps JavaScript API(v3) and I'm hitting
I'm writing a web application using the google maps api v3, which displays places
I'm using Google Maps API on my ASP.NET Web Application. Currently the center position
I am developing web-application using Google Maps API and ASP.NET Ajax. Here is my
When I check the website, I see that web application using Google maps API
I'm trying to optimize my web application using Google's Page Speed API which has
I am planning to build a web application highly based on Google Maps API.
I'm creating a not-web application using C# and I would like to use Google
Google's usage guidelines state: Web sites and applications using each of the Maps API
Hi I have one web application where i am using google map in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.