Solved

Dynamic Google Map in Bootstrap Modal

Posted on 2016-11-21
7
18 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
Comment Utility
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 9

Expert Comment

by:Prasadh Baapaat
Comment Utility
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
Comment Utility
$("#myModal").on("shown.bs.modal", function () {initialize();});

Is initialize defined?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 5

Author Comment

by:Neil_Bradley
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Understood and thank you. Your comment lead me to a great solution.
Cheers,
Neil
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now