Skip Navigation

[Resolved] How do I display a map with PHP?

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.85 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by amandaD 4 years ago.

Assisted by: Minesh.

Author
Posts
#1824213

Sorry, I have searched your site and all I can find is shortcodes and tutorials on using the Block editor.

I am building a custom single post template page in PHP and I need to display my Google map showing the single listing as a marker on the map. Where do I find the documentation for that?

I've been trying to use this:

<div id="js-wpv-addon-maps-render-my-map" style="width:400px; height:200px;" class="wpv-addon-maps-render js-wpv-addon-maps-render js-wpv-addon-maps-render-my-map " data-map="my-map" data-generalzoom="6" data-generalcenterlat="0" data-generalcenterlon="0" data-fitbounds="off" data-singlezoom="15" data-singlecenter="on" data-maptype="roadmap" data-showlayerinterests="false" data-markericon="" data-markericonhover="" data-draggable="on" data-scrollwheel="on" data-doubleclickzoom="on" data-maptypecontrol="on" data-fullscreencontrol="on" data-zoomcontrol="on" data-streetviewcontrol="on" data-backgroundcolor="" data-cluster="on" data-clustergridsize="60" data-clustermaxzoom="" data-clusterclickzoom="on" data-clusterminsize="2" data-stylejson="//toolset.com/wp-content/plugins/toolset-maps/resources/json/Standard.json" data-spiderfy="off" data-streetview="off" data-markerid="" data-location="" data-lat="0" data-long="0" data-heading="" data-pitch=""></div>

but the shortcode documentation doesn't tell me much about

map_id

- is this an ID that I make up and just needs to be unique, like any other html ID, or is it looking for a specific ID ?

The above code is supposedly the shortcode for

wpv-map-render

but it doesn't render anything - just a blank rectangle and no error messages in the console.

I have the address and lat/long co-ordinates - I just need to know how to actually render the map. I was previously using my own map, but that clashes with Toolset Maps (errors about including the maps API multiple times on the same page).

#1824779

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no PHP API available to display the Toolset Map using PHP.

- is this an ID that I make up and just needs to be unique, like any other html ID, or is it looking for a specific ID ?
==>
yes, the map ID should be unique.

To display the map inside your PHP template there are couple of ways.

Either you should create a view that display your map and use the View's PHP API function: render_view()
=> https://toolset.com/documentation/programmer-reference/views-api/#render_view
Or
You should create a content template that hold your Map and use the function: render_view_template() that should render the content template:
=> https://toolset.com/documentation/programmer-reference/views-api/#render_view_template
Or
You can use do_shortcode() function to render the map shortcodes:

echo do_shortcode ('[wpv-map-render map_id="map-1"]');
echo do_shortcode ('[wpv-map-marker map_id="map-1" marker_id="marker-1" marker_field="wpcf-address"][/wpv-map-marker]');

Where:
- wpcf-address is the address custom field that holds the value of address string. Where you should just replace wpcf-address with your original address field.

Obviously - what method should be used is depends on your requirement and how you want to display the map.

#1825341

Thank you - the shortcode solution worked perfectly (after a bit of tinkering).