My client is having an issue where the distance for some of their locations is not appearing on the Locations card even though the users computer is set to share location. For some locations it works, but for some, the distance only appears once the location facet has been applied.
In a conversation with someone from Tech Ops, they shared this:
d_distanceFromFilter only returns when a location filter is applied, which is why you’re not seeing it displayed on all results.
If you’d like to display the distance from the user’s derived location, you can update that to just distance: Formatter.toMiles(profile) (the formatter falls back to use the d_distance field). Furthermore, you can do some conditional logic to check if a d_distanceFromFilter exists, and if so, use it, otherwise fallback to d_distance .
However, neither worked. I was directed to post in the Community if there were any errors, so would appreciate any insight in to what might be going wrong here.
If the formatters-internal is already forked, you can go ahead and modify that file. Find the toMiles function in that file, and replace it with the above snippet, and that should do the trick!
It looks like I’m getting an error on the ?? and the if statement below from copying in the code above (see the previous toMiles function commented out below).