Load Google Map on Click
-
Hello, I am trying to optimize the charges hitting my Google Maps API key. As a result, I thought I could prevent the Google Map from being loaded into the DOM of the web page by creating a button that would dynamically load the Google Map with markers into the DOM on button click.
As a result, I tried creating a custom Map Template within my custom WordPress theme. The first thing I tried to do was remove the following map element from the template to see what happens.
$output .= "\t" . '<div id="wpsl-gmap" class="wpsl-gmap-canvas"></div>' . "\r\n";
After refreshing the page, my list of Restaurants disappeared alongside my map even though the
#wpsl-result-list
elements were left untouched.Is what I am attempting to do not possible with this plugin? If the Restaurant posts depend on the map being rendered in order to know what its data is going to be… then I can’t prevent the Google map from being rendered in the DOM and expect the posts to function the same way as it does when the map is present… right?
Once again, the reason I want users to control the loading of the map into the DOM is to optimize the Google Map API charges I am receiving by always rendering the map. Logically, I don’t want the map to render unless the user chooses to interact with it.
- The topic ‘Load Google Map on Click’ is closed to new replies.