Solved

Dynamic Google Map in Bootstrap Modal

Posted on 2016-11-21
7
87 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 53

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 53

Expert Comment

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

Is initialize defined?
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Industry Leaders: 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

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 Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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)

724 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