?
Solved

Dynamic Google Map in Bootstrap Modal

Posted on 2016-11-21
7
Medium Priority
?
173 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 54

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 54

Expert Comment

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

Is initialize defined?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 83

Accepted Solution

by:
leakim971 earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 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