Skip Navigation

[Resolved] Display a marker at the location entered as “distance search center”

This thread is resolved. Here is a description of the problem and solution.

Problem

How can I produce a map, with the address as the centre of the map (if there are no results) which the user gave as his location?.

Solution

To display the address that the user gave as "his centre", you can listen to the URL parameter `toolset_maps_distance_center`.

It results in a ShortCode like this:

//Render the Map
[wpv-map-render map_id="map-UNIQUE!!"][/wpv-map-render]
 
//Render the marker with address the center given
[wpv-map-marker map_id="map-UNIQUE!!" marker_id="marker-UNIQUE!!" address="[wpv-search-term param='toolset_maps_distance_center']"][/wpv-map-marker]

==> Adapt UNIQUE!! to unique IDs
(map_id must match, marker_id must be unique again)

This support ticket is created 6 years, 10 months 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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#625638

In a view I use the filter by distance feature. If nothing has been found near the center (entered by a visitor), in the [wpv-no-items-found] section I would like to display a marker at the "center" location the user typed in.

Question 1: How can I access that value?

Furthermore, it doesn't seem possible to pass in a dynamic value via shortcode to set a markers position. I tried the following:

[wpv-map-marker map_id="map-1" marker_id="marker-none" marker_title='Nothing found' address='Berlin, Germany']Nothing found[/wpv-map-marker]
--> working, shows a marker labelled "nothing found" in Berlin

When queried via URL param (&center=Berlin):
(i renamed the url param to "center" and created a shortcode to access query vars)

[wpv-map-marker map_id="map-1" marker_id="marker-none" marker_title='Nothing found' address='Berlin, Germany'][my-query-var var="center"][/wpv-map-marker]
--> working, shows a marker labelled "Berlin" in Berlin

[wpv-map-marker map_id="map-1" marker_id="marker-none" marker_title='Nothing found' address='[my-query-var var="center"]'][my-query-var var="center"][/wpv-map-marker]
--> not working, doesn't show any marker at all

Question 2: How can the address attribute of a marker be set via shortcode in the mentioned scenario to represent the location entered by a visitor?

Thanks,
Sebastian

#625835

You do not need to create a ShortCode or rename the Quer Vars to access them.
Toolset already provides this:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

To display the address that the user gave as his centre, you can do it like this:

[wpv-map-render map_id="map-UNIQUE!!"][/wpv-map-render][wpv-map-marker map_id="map-UNIQUE!!" marker_id="marker-UNIQUE!!" address="[wpv-search-term param='toolset_maps_distance_center']"][/wpv-map-marker]

Adapt UNIQUE!! to unique IDs
(map_id must match, marker_id must be unique again)

This will return a map, with the queried address as it's centre if there are no results.