![]() * Add the Maps JavaScript script in the footer. Ive added an option into Divi Booster to prevent excerpts from loading the Google Maps scripts unnecessarily. I have google maps JS API script enqueued succesfully, with its API key in app/setup.php. Doing the same as in Sage 8, doesn’t work in Sage 9. $wptgmap_have_assets_been_enqueued = true Ive created an option tab with Advanced Custom fields where you can paste your Google Maps API key, so I dont have to put the API key in the code over and over again when starting a new project. Trying to get Google maps JS API working. Enqueue the Google Maps JS in the footer.Īdd_action('wp_footer', 'wptgmap_page_footer', 99) '/wpt-google-map/wpt-google-maps.js', null, $version) Enqueue our frontend JavaScript and set the wptgmapData to hold '/wpt-google-map/wpt-google-maps.css', null, $version, 'all') Back in your child theme’s main folder, create new filed called “ wpt-google-map.php” and paste the following into it. This may cause unexpected errors.,Im developing a plugin that use a Google Maps API. In here, create two empty files, called “wpt-google-maps.css” and “wpt-google-maps.js”. Go to your custom child theme’s main folder and create a new folder called “wpt-google-map”. The only fiddly bit is adding the map markers, as we need to do some to-ing and fro-ing with the Google Places API, but we’ll get the basic maps working first. We’ll put our JS and CSS in separate asset files, and we’ll hook WordPress’ wp_footer action to inject the Maps JavaScript script element at the end of the page. We’re going to create a shortcode that’ll output a div element, with the data-map="." property holding the parameters of the map. Starting our callback : wptgmapInitMaps()') ĭocument.querySelectorAll('.map').forEach(function(container) " property as JSON. Here’s a rough outline of how the HTML will look: Ĭonsole.log('Maps API loaded. When your JavaScript function is called, use the Google JS to initialise your map div element(s).Detecting request type in PHP (GET, POST, PUT or DELETE) 1116. The URL should contain the name of a function in your page’s JavaScript, which will get called when the Google script has finished loading, e.g. Loading Google Maps API with wpenqueuescript. At the end of the HTML, add a script element that pulls in the Google Maps JS.We’re going to use a CSS class to do this, so we can select all the maps on a page with a single query. Google Maps Platform gives apps the ability to include the features and functionality of Google Maps, such as displaying maps, retrieving place data. However, I want my code to run the query that produces the GeoJSON data, and I know how to do that in php. I'm using Xampp to load Apache and view files on my browser. This is just a div that can be identified with a CSS selector. html the map shows up just fine, and it shows the data I want to see (a Linestring). Create an HTML element on your page that will act as a “container” element for the maps.The Google documentation for the Maps JavaScript API outlines how to get a map into your page, and the process works like this: The rest of the php code is not a problem, but that line (even commented) breaks everything.Restrict by HTTP Referrer How It’s Going to Work You can rate examples to help us improve the quality of examples. (window, "load", initMap) Īfter a some time of trying things I noticed that the problem seems to be when I add this line //var json_data = "" PHP etpbenqueuegooglemapsscript - 3 examples found.These are the top rated real world PHP examples of etpbenqueuegooglemapsscript extracted from open source projects. Map = new (document.getElementById('map'), , But as soon as I change the extension to php, it breaks. html the map shows up just fine, and it shows the data I want to see (a Linestring). I've been trying to load some GeoJSON data into a map, using Google Maps API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |