Tell us what you are trying to do? I have a custom post type (therapist listing) that has up to three locations / street addresses as values/fields. Think of this as a directory listing, with multiple service locations. The views search appears to work fine, and will check all three when searching, and return the listing/post if at least one of the three addresses falls within the search radius. The listings that return all show the primary/first street address though, and what I would like to happen is instead the show the address that is closest/matching search options. E.g. if #2 street address for a listing falls within the search radius, when the listing is shown in the results, have that street address appear. If there are more than one street address for the listing that fall within the search radius, show the first one that is found as part of the results (not them all).
Is there any documentation that you are following? Just looking at example Toolset sites
We have an imminent release of Maps 1.6 which covers some of the issues you talk about here, and I would like to do some testing with that version to see if it changes anything.
OK, I set up a test with Maps 1.6 to look at what you are describing, and I don't see any way of achieving what you want.
The distance filtering is part of Views and Maps.
Remember, what's going on here is that you set up a View to query for posts where the address falls within the map search radius (and it is able to handle the case where a post has multiple address fields, and only one of them needs to fall within the search radius for the post to qualify).
So the query returns a list of matching posts, and then we iterate over them to output the desired fields.
When it comes to outputting the address, that is done with the types shortcode, which provides a separator attribute to specify how multiple field values should be displayed. But the shortcode is ignorant of the distance calculations that were performed relative to the search location by the View. It is not possible to order the multiple field values accordingly, and it is not something that is readily customisable.
If you have a business listing, and that business has several locations, I think what you would need to do is to make a post type for the location which has an address field and which is a child post of the business. Your location search would then query the location posts directly (rather than the business posts) by distance, and when iterating over the results you could output fields from the parent business alongside the address & distance fields for the child location posts.
Thanks for going through this, and I understand what you are saying. I do have a question though: How does sorting by location/distance work? Surely there is some distance value used there? Although inefficient, do you know of a way to have each of the results when rendering have their distance recalculated against the search filter, and show the shortest distance?
Side question that has just come up from me thinking about this -- one of the addresses ends up showing up on the map, is this the shortest distance one, or the first one found? And secondly, any way to make that pinned location on the map have a hover-over/on-click with some of the details of that result?
The distance filters work in two stages. First, all posts of the type being queried have their distance calculated to narrow the universe of possible posts down to the ones within the search radius. This list of posts, which may be sorted by distance, is then passed to the standard query (built on WP_Query) where any other filters are also applied and the ordering maintained.
To display the distance you can insert this via the Fields and Views button which will insert the new toolset-maps-distance-value shortcode, which will calculate the distance of the current post to the specified location (which may be the location entered in the search filters).
In my testing I found that when there are multiple addresses the distance it displayed was the shortest distance, i.e. the lowest of the distances for all values of the address field, but you should double-check that yourself with your own data to be sure.
Here is what I am wondering: if it's possible to show the distance value (through that shortcode), I wonder if we can use that shortcode as part of a conditional statement, to show the street address it matches? Thoughts on this? Trying to come up with a solution with all the tools at hand, even if not elegant.
Thinking it through I can't see a solution—inelegant or not—based upon repeating address fields.
I think you need a solution that uses child posts (or address fields in repeatable field groups, which is essentially the same thing), I can't see any alternative.