Skip Navigation

[Resolved] Map search with state names from autocomplete

This support ticket is created 4 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1654305

Tell us what you are trying to do?
Basically we are using autocomplete on all our search forms (Toolset and otherwise). The homepage (hidden link) search map is powered by Toolset, and the radius search works up to a point for street, postal code, city type addresses. But we want it that when a user selects a state name from autocomplete, that all results within the state display on the map. This already works for countries in Toolset map. On the homepage when I select India I see both listings in that country but when I select "Maharashtra India" or "Gujarat India" I do not see either of the one listing that should appear in both states, this is the same with other countries: "Vermont, United States" returns empty results while just "United States" works. I am assuming it is trying to do a radius/distance search for states too which is kinda impractical for a large geographical area. Since country name search works, I hope there is a way to apply the same to state names?

Is there a similar example that we can see?
hidden link
This is a form generated via WP Job Manager + GeoMyWP combo, for "country" and "administrative_area_level_1" (states) they ignore distance search and directly match state and country codes in address components fields in DB, which makes sense.

What is the link to your site?
hidden link

#1654687

Hi, the Toolset Maps distance search feature isn't going to work well with country or state names. It's designed to work best with more specific points that can be geolocated using a pair of latitude and longitude coordinates, like a street address or city name. I'm not exactly sure why it seems to be returning results when selecting a country name in your case, but my guess is it could be related to the other filters in the View, or custom code that is applied using JavaScript. As your site's content grows you will find that selecting a country name does not consistently provide accurate results in a distance-based search filter, nor do we expect it to.

The only other autosuggest field offered in search Views is provided to search for a related post by title. If you wanted to implement one of these for location-based searches, you would have to split up "State" into its own custom post type and create a post relationship between each State and the post that appears the View results. Managing that relationship in wp-admin would have to be manual, because when Toolset Maps geolocates an address in an address custom field, the individual address components are not separated. The entire formatted address is stored as a single unit. To separate out individual components you would need to implement a significant amount of custom code including JavaScript and PHP. An example splitting the postal code into a separate custom field can be found here: https://toolset.com/forums/topic/separating-content-from-the-address-field/
Creating or managing a post relationship instead of a custom field would be significantly more complex, plus combining this filter with a distance search may not be practical. It would be confusing to have two input fields in the search area that seem to offer similar search criteria. So the short answer is there really isn't a built-in way to use an autosuggest field to search for posts within a specific state or country.

If you'd like to see search-within-state, search-within-country, or search in bordered areas features added to Toolset Maps, I encourage you to submit your request to our management team: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset

#1657021

Thanks for getting back to me. We already have them in separate custom fields thanks to integration with GeoMyWP. I have a workaround in mind, the other map on the same site does it perfectly, which is have a state and country code field hidden in the filter form, when Google autocomplete geocodes into a place that is either country" or "administrative_area_level_1", then save their values in those hidden fields, and when those are not empty, just match their values in the DB without the distance filter. I had something like that working for a while some time ago when neither state or country searched worked in Toolset map, but then I realised that something changed in the Maps add-on that the country filter worked automatically so I wanted to ask if the state can work the same way too. Since you are not sure why it works, I will go back to the original solution I was working on.

I would still like to suggest having something like this done automatically in Toolset Maps, it makes a lot of sense since the autocomplete lets you select any kind of place, small or large!

#1657101

Understood - this feature would be quite powerful. Let me reach out to my team leader and see what else, if anything, I can offer.

#1663377

In tests on our local sites, selecting a country from the dropdown field does not produce results. We're not exactly sure why it works on your site, but it probably has to do with other search criteria and custom code. My team manager has reviewed the request and noted that we can make this request from our developers but it will require a considerable amount of work and probably won't be included in the near future.

#1667913

OK, thanks a lot of the consideration and I hope at some point in the future we are able to do this without custom coding. Thanks for your help Christian.

#1668749

Closing here