Google Maps in Modal.

2 replies · opened Jul 27, 2016

CCircus33Jul 27, 2016

Hi, Im trying to add google maps in a modal, however the maps window is showing but the map is loaded into the top right corner and I can't move it at all.
Any help please :) ? Here is my code for the map and the modal.

$('#google-map1').gMap({
			address: 'ul. Radetski 2, 3001 Vratsa, Bulgaria',
			maptype: 'ROADMAP',
			zoom: 17,
			markers: [
				{
					address: "ul. Radetski 2, 3001 Vratsa, Bulgaria",
					icon: {
						image: "images/icons/map-icon-red.png",
						iconsize: [32, 39],
						iconanchor: [32,39]
					}
				}
			],
			doubleclickzoom: true,
			scrollwheel: false,
			controls: {
				 panControl: true,
				 zoomControl: true,
				 mapTypeControl: true,
				 scaleControl: true,
				 streetViewControl: true,
				 overviewMapControl: true
			}

		});

  
    
      
        ×
        Modal title1
      
      
        
      
      
        Close
        Save changes
      
    
  
SSemicolon WebSTAFFJul 28, 2016

Hello,

Since the Google Maps and Modals both are initiated using jQuery, there can be some conflicts. You will need to Re-Initialize the Google Maps JS in order to be shown inside the Modal Window. Consider using the following HTML Code:


Launch modal

	
		
			
				
					×
					Google Map
				
				

					

				
				
					Close
					Save changes
				
			
		
	

and then add the following JS Code at the bottom of the Page just after the js/functions.js JS File Linking:


var gMapShowed = 0,
	showGmap = function() {

		if( gMapShowed == 1 ) { return true; }

		jQuery('#google-map').gMap({

			 address: 'Melbourne, Australia',
			 maptype: 'ROADMAP',
			 zoom: 14,
			 markers: [
				{
					address: "Melbourne, Australia"
				}
			 ],
			 doubleclickzoom: false,
			 controls: {
				 panControl: true,
				 zoomControl: true,
				 mapTypeControl: true,
				 scaleControl: false,
				 streetViewControl: false,
				 overviewMapControl: false
			}
		});

		gMapShowed = 1;

}

jQuery('#gMapModal').on('shown.bs.modal', function () {
	showGmap();
});

This will definitely work fine. Let us know if we can help you with anything else or if you find any further issues.

CCircus33Aug 1, 2016

AWESOME!!! Thanks a lot guys! It works like a charm.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard