Marko Ćilimković
Marko Ćilimković

Reputation: 753

Initializing google map depending on form results

So I have a form with just a select field. Depending on what the user selected markers will get rendered through AJAX on the map. The thing is how to initialize the function and create the map.

I just found that people are doing it this way:

google.maps.event.addDomListener(window, 'load', initialize);

So the map is initialized when a full page reload finishes. What I need is to call the initialize function and create the map when an ajax request is done performing. How can one achieve this? :)

Upvotes: 0

Views: 32

Answers (1)

kaho
kaho

Reputation: 4784

Well, there are several ways on doing that. you can set a promise, or a listener to your AJAX, but the simplest way to do that is just call initialize() at the end of your AJAX code.

Since google.maps.event.addDomListener(window, 'load', initialize); basically has the same effect with <body onload="initialize()">, or $( document ).ready(initialize()), so you should be able to call the initialize() whenever you want.

Upvotes: 1

Related Questions