Google map problem in jQuery popup

Hello,

I've been struggling around with an issue that seems to be very simple but it turned out to be a nightmare :D. All I wanted to do is to place a google map inside a jQuery modal popup. The problem that it wasn't displaying the map correctly, then after searching the problem, it turned out to be that google map could not be displayed in a hidden div, so the solution was to hide the div by adding a style to it as:

left: -10000px

And by using a popup like this one (Fancy box), you’ll get the map to display correctly J

Here's a Working example:

<html>

<head>

    <title>Map in FancyBox popup</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

    <meta charset="UTF-8">

    <style type="text/css">

        #container

        {

            left: -100000px;

            position: relative !important;

        }

        #map_canvas

        {

            margin: 0;

            padding: 0;

            height: 500px;

            width: 500px;

        }

    </style>

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

    <script type="text/javascript" src="jquery.fancybox-1.3.4.pack.js"></script>

    <script type="text/javascript" src="jquery.mousewheel-3.0.4.pack.js"></script>

    <link rel="stylesheet" href="jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

    

</head>

<body>

    <a id="inline" href="#map_canvas">Open Map</a>

    <div id="container">

        <div id="map_canvas">

        </div>

    </div>

</body>


<script type="text/javascript">

    var map;

    function initialize() {

        var myOptions = {

            zoom: 8,

            center: new google.maps.LatLng(-34.397, 150.644),

            mapTypeId: google.maps.MapTypeId.ROADMAP

        };

        map = new google.maps.Map(document.getElementById('map_canvas'),

            myOptions);

    }


    google.maps.event.addDomListener(window, 'load', initialize);

    $("a#inline").fancybox();


    </script>

</html>

​​​​​

Cheers,

 

posted @ Wednesday, October 12, 2011 5:25 PM
Print

Comments on this entry:

# re: Google map problem in jQuery popup

Left by Ramy Gamal at 10/13/2011 12:40 PM
Gravatar
Thanks Hani it really helped me :)

# re: Google map problem in jQuery popup

Left by clear window stickers at 10/14/2011 9:17 PM
Gravatar
Google Maps API V3 doesn’t require any API key and is really easy to use already.
thanks..
sticker printing | [url=http://www.printinghost.com/Stickers-printing.html]sticker printing[/url]

# re: Google map problem in jQuery popup

Left by custom stickers at 3/8/2012 12:48 AM
Gravatar
I ma funny agree with the above comment, there is no need of API in V3.
Good time

sticker printing

# re: Google map problem in jQuery popup

Left by jasmeet at 4/19/2012 4:30 AM
Gravatar
Can you please share some example for displaying map on JQuery popup or fancy box popup.

# re: Google map problem in jQuery popup

Left by H@Ni at 4/24/2012 10:27 AM
Gravatar
@jasmeet Sorry for late replying but i was busy for a while, I'll work an example and post it for you today :)

# re: Google map problem in jQuery popup

Left by Ant Cruz at 5/18/2012 5:55 PM
Gravatar
Good post, Working...!!!!!

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«May»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789