Link to home
Start Free TrialLog in
Avatar of Neil_Bradley
Neil_BradleyFlag for New Zealand

asked on

Dynamic Google Map in Bootstrap Modal

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
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

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

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?
$("#myModal").on("shown.bs.modal", function () {initialize();});

Is initialize defined?
Avatar of Neil_Bradley

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Understood and thank you. Your comment lead me to a great solution.
Cheers,
Neil