Solved

Dynamic Google Map in Bootstrap Modal

Posted on 2016-11-21
7
44 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

803 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