Does anyone have a straight-forward explanation of how to display a Google Map on a custom post type?
I’ve read through the documentation but I am a bit lost.
I am creating a website for an apartment property management company and have created a custom post type of “Properties”. I have ACFs for each of the items (Address, number of bedrooms, paerking, gallery, etc) and have them all working. But I can’t seem to get the map to display.
Any help would be appreciated.
Suggest you to use the google map field for the address.
ACF will also return you the longitude and latitude along with the address. With the longitude and latitude, then you are able to work with google map. Because to add a pin(marker) on google map, it requires a longlat value.
take a look at the google map field documentation.
The documentation for the google maps field gives you everything you need to get it working.. You can basically copy the entire example and just switch out the field name.
All the JS goes in your themes script.js file (or similar) and the PHP/HTML in the template file you want the map to be displayed in. It would need to be inside the loop of the page where the field is applied in admin just like any other ACF field (Or set the second parameter which is the post ID).
I got Google Maps showing gray (https://ibb.co/mhsPs7) after copying all the required code given at https://www.advancedcustomfields.com/resources/google-map/
into an single post template, entering an address in the map field and replacing every $location value to the one set in the ACF edit screen.
The Console tab of Chrome/Firefox returns no error. Would someone please shed some light on this? I spent two days and am not getting anywhere….
Code is below, and also available as a gist here. Because it uses both the JS API and Embed API, you’ll need to generate keys for both.
To make the map, all you’ll need to do is call acf_make_map( get_field( ‘your_google_map_field_name’ ) );
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!