Skip Navigation

[Resolved] Sort custom type list by distance to location

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 23 replies, has 3 voices.

Last updated by dimitriH 1 year, 11 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2283719

Tell us what you are trying to do?
We have set up a list of restaurants (custom types).
We added geo location to show the user the distance between his current location and the restaurant
Now, I'm looking for a solution to sort the list using the provided geo location.

What is the link to your site?
hidden link

#2285085

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Toolset does not have a built-in Geo Location functionality. The only way that I see a geolocation work with maps and the post listing is that the plugin or system that you use, add the Lat and Long of the users location to a Toolset custom field.

Then you will be able to use that custom field to sort your listing. But it is outside of our support scope as we do not know how you implemented the Geolocation.

You are welcome to hire a developer to integrate your geolocation system with Toolset:

https://toolset.com/contractors/

#2285637
longitude-latitude.jpg

Hi Christopher,

Are you sure what you state is accurate?
If I look at Toolset's changelog, Geolocation functionality was added in v1.4 (December 7, 2017).

I set up the address-field using the wizard's 'Address' field option.
It is showing Latitude and Longitude when you click 'Show/hide coordinates'.
Please find screenshot in attachments.

When using the following shortcode (I got it from your documentation), I'm able to show the distance between the user's location and the restaurant.
[wpv-geolocation message_when_missing=" "]
[toolset-maps-distance-value origin_source='visitor_location' postmeta='wpcf-google-map-address'] km van uw locatie
[/wpv-geolocation]

So, if I can show the distance between 2 points and the longitude and latitude values are present, I feel I should be able to sort them as well.

I can even set the order in the view to:
Order by 'Field - Google map address (the field that is showing long and lat) - ASC - As a distance from - Visitor location'.

But the order is incorrect.

#2286761

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I see, you are talking about the Geo-Location in the context of the Map.

To make sure I know what is the setup I'd appreciate it if you can give us the login information of your website and which page to check for the restaurant listing and see the result.

You can set the next reply as private to give the info.

#2287655

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the login information. I checked and asked for a second opinion and will get back to you shortly.

Thank you

#2287657

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the login information. I checked and asked for a second opinion and will get back to you shortly.

Thank you

#2288423

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

After the investigation by the second tier, it seems that the issue is happening on your installation and not a clean installation.

Out team is investigating the issue, but as it might be many causes, we are not sure and doing our best. That might take some time.

We will get back to you as soon as we have a result.

Thank you.

#2296401

Hi Christopher,
Do you have an update on the issue by any change?
Cheers

#2297981

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Unfortunately, the issue is deeper and it relates to the Google API itself:

https://toolset.com/errata/search-by-distance-may-produce-wrong-results/

Would you please try the method below that mentioned in the errata and see if it works for you?

An alternative would be to use the Azure Maps API instead.

As this is a rare case, we do not have any ETA for a fix.

Thank you.

#2298765

Hi Christopher,

Are you sure what you state is correct?
You point me to documentation talking about Google geocoding API returning incorrect results.

I feel that's not our issue.
All map markers are correct, so the API is returing the right locations.
When a user passes his current location, the distances between the user and the locations are calculated correctly (FYI: I've added them in red to the view)

We set the view to 'Order by 'Field - Google map address (the field that is showing long and lat) - ASC - As a distance from - Visitor location'.
But the order is incorrect.

#2299937

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the correction. I mixed up with the other issue. I checked and as this is happening only on your installation we are unable to find the reason behind it.

The development team will look into the matter depending on the priorities that they are given.

At the moment I do not have an ETA.

Thank you.

#2301173

Hi Christopher,

I've set up a clean install for you.
Would you mind looking at that one? Because I'm still having the same issue.
It has WP latest version and the relevant Toolset plugins, nothing else.
I also limited the custom fields so they only show Name, Google map address and front-end address.
Front-end address is a simple string we want to show on the front-end to have better control.

It doesn't matter which distance-based order I select.
The items are always shown from old to new.
I tried with a fixed location as well, but still no change.

When I change the order to be string-based (A-Z), it works.

Since all pins are marked in the right location and distances are being calculated correctly, I still feel the issue is on your end.
Anyway, thanks for checking our clean install. If you could open a private comment, I'll add the credentials.

#2301665

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

The issue is on our end. The problem is that our dev team could not replicate the issue on a clean installation.

But I suggest that you also try the same thing in a clean installation that I provide as it is recognized by our team.

Would you please try to log in here and see if you can replicate the same issue?

hidden link

Also, I enabled the private mode for the next reply, but if you can replicate the issue in the clean installation above it will a good ground to add to report.

Thank you.

#2301807

I've set up your sandbox. Same issue...
Location order is Old to New when I select 'order by distance from user location'.
If I change it to string-based order, it is working fine.

I've created a new page to show the view: hidden link

Thanks again for checking.

#2302023

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the details. We checked the clean installation we do see the issue. We also checked the same on our clean installation and the issue is not there.

Problem:

hidden link

Correct:

hidden link

This will be investigated by our development team. But as the issue is not possible to replicate on our clean installation it might take some time.

There is no ETA.

Thank you for your understanding.

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