Solved

Dynamic Google Map in Bootstrap Modal

Posted on 2016-11-21
7
56 Views
Last Modified: 2016-11-22
Hi EE.
demo page here.
On button click a Modal appears but my Ajax Google does not initialize.
Close the modal then click again and the map appears.
How do I get my map to appear when the Modal first appears?
Cheers,
N
0
Comment
Question by:Neil_Bradley
7 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 41896955
Check your browser console
ncaught ReferenceError: initialize is not defined(…)(anonymous function) @ map-modal.html:149dispatch @ jquery.min.js:4r.handle @ jquery.min.js:4trigger @ jquery.min.js:4e.event.trigger @ jquery-migrate.min.js:2(anonymous function) @ jquery.min.js:4each @ jquery.min.js:2each @ jquery.min.js:2trigger @ jquery.min.js:4(anonymous function) @ bootstrap.min.js:6d @ jquery.min.js:4handle @ bootstrap.min.js:6dispatch @ jquery.min.js:4r.handle @ jquery.min.js:4
util.js:210 Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keysRA.j @ util.js:210(anonymous function) @ js?sensor=false&_=1479791290821:126(anonymous function) @ js?sensor=false&_=1479791290821:46(anonymous function) @ js?sensor=false&_=1479791290821:43(anonymous function) @ js?sensor=false&_=1479791290821:46(anonymous function) @ js?sensor=false&_=1479791290821:98(anonymous function) @ js?sensor=false&_=1479791290821:43(anonymous function) @ js?sensor=false&_=1479791290821:98hc @ js?sensor=false&_=1479791290821:45gc.nb @ js?sensor=false&_=1479791290821:98(anonymous function) @ stats.js:1
util.js:210 Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-requiredRA.j @ util.js:210(anonymous function) @ js?sensor=false&_=1479791290821:126(anonymous function) @ js?sensor=false&_=1479791290821:46(anonymous function) @ js?sensor=false&_=1479791290821:43(anonymous function) @ js?sensor=false&_=1479791290821:46(anonymous function) @ js?sensor=false&_=1479791290821:98(anonymous function) @ js?sensor=false&_=1479791290821:43(anonymous function) @ js?sensor=false&_=1479791290821:98hc @ js?sensor=false&_=1479791290821:45gc.nb @ js?sensor=false&_=1479791290821:98(anonymous function) @ stats.js:1

Open in new window

0
 
LVL 10

Expert Comment

by:Prasadh Baapaat
ID: 41896956
I see that you are loading another php page in the modal and in that page the google map is loaded... why cant you load the map in modal directly?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 41896957
$("#myModal").on("shown.bs.modal", function () {initialize();});

Is initialize defined?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 5

Author Comment

by:Neil_Bradley
ID: 41897027
Hi all,
My modal links to a page containing the a map. I will eventually have over 30 links on this page each going to their own map so hence my solution.
I have tried adding this $("#myModal").on("shown.bs.modal", function () {initialize();}); to the page containing the map and to the page containing my Modal button but the results are the same. The map only appears in the Modal window on the second opening of the Modal
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 41897047
The alternate solution I have found is to dynamically pass the lat and long coordinates from the modal button to the map. While this seems to work it still need to figure out how to get my info window back..
Alternate solution
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41898271
why are you storing only lat and lng and not the data for the infowindow ?
or
just a key or Id or Index (no matter its name) as reference of an array of object. this array is global to your page

var markers = [
        {
             title: 'Volivoli Beach Resort', 
             lat:-17.311925,
             lng 178.174725, 
             zindex:1,
             html: '<div class="scrollFix"><p><strong>Volivoli Beach Resort<\/strong><\/p><\/div>',
             icon: 'marker.png'
         },
        {
             title: 'other place', 
             lat:-18.311925,
             lng 175, 
             zindex:1,
             html: '<div class="scrollFix"><p><strong>other place<\/strong><\/p><\/div>',
             icon: 'marker.png'
         }
];

Open in new window


and your links just have an index to the marker :

<a data-marker="0"...
<a data-marker="1"...
0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 41898501
Understood and thank you. Your comment lead me to a great solution.
Cheers,
Neil
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question