Skip Navigation

[Resolved] Add a marker based on a search field OR current location

This support ticket is created 4 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by davidM-26 4 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1474383

I have a search page setup. It's pretty standard and "works"

What I want to do is both centre the map and have a marker on the location the user sets.

This is easy if they press "use my location".

But what I don't get, is what if the actually type in the location instead? What if the want to see records 5km from their mum's house? They would type that in - but then how does that field get displayed as a marker? And, get centred?

I hope I've explained that correctly.

#1474855

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi David

When a user enters their location in a search, e.g. they type in their mum's address, what happens is the search is performed (retrieve posts within 5km of said address), and let's say that returns 3 results. Those 3 results are then displayed on the map, and the map is centred on those results. So, clearly the map will be close to their mum's address, but it won't be centred on it, it will be centred on the results. And if all of the results were give-or-take-a-few-metres 4.9km to the east of their mum's house, then the map would be centred 4.9km of that address.

Does that explain how it works satisfactorily?

#1474859

Sort of - what I wanted to do was add a marker for their location (so they could see it in relation)

You can put a marker for the current persons location, but not if they manually enter one.

#1474957

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

When a user submits a distance search then a several URL parameters gets added, including toolset_maps_distance_center, which is the address entered for the search.

So we can use that to add a marker at that address, e.g.

[wpv-map-marker map_id='map-1' marker_id='marker-2' address='[wpv-search-term param="toolset_maps_distance_center"]'][/wpv-map-marker]

Add that in the same place as the map shortcode, i.e. outside of the loop so that it is only added once.

If a search hasn't been made yet (initial page load), then no marker will be shown.

Will that work?

#1475617

Thank you Nigel! That is perfect.
I think it's logical that if the person uses an alternate address other than ":use my location" you should be able to show that and you did it for me! Thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.