orderBy=geo_distance not ordering by distance

SOLVE
Highlighted
Regular Contributor

We are building a resource locator. The user can filter on services provided and we'd like them to be able to order the results by distance from a searched address. The filters work, the geolocation works* (the build that is not yet pushed to the url above), and the orderBy distance is not. 

 

This is the query in the code: 

Screen Shot 2019-07-12 at 6.13.34 PM.png

 

And according to hsDebug=true* this is how the query is sent:

Screen Shot 2019-07-11 at 5.36.40 PM.png

What am I missing that is causing the orderBy to not work? 

 

*Thank you to @Jsum  and @lscanlan for helping me figure out how to persist the lat and lon from the google maps api.

**Thank you to @mcoley  for the hsDebug=true tip. That extension is a lifesaver!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Regular Advisor | Partner

@JAbella are you viewing a page with the query parameters at the end of the url? It looks like it might be empty. e.g. example.com/map?latitude=123&longitude=321

Stefen Phelps, Community Champion, Kelp Web Developer
Reply
0 Upvotes
4 Replies 4
Highlighted
Regular Advisor | Partner

@JAbella have you tried it without the "mi"? I don't think that part is needed. The example in the documentation looks like this:

orderBy=geo_distance(location_column,42.37,-71.07)
Stefen Phelps, Community Champion, Kelp Web Developer
Reply
0 Upvotes
Highlighted
Regular Contributor

Thanks @stefen  -- removing the mi doesn't change the ordering of the returned rows.  Sort of related, when I remove the additional filters, and try to sort everything, I get this error: 

 

Screen Shot 2019-07-15 at 10.48.26 AM.png

 

Does that mean there's an error with my location column? There are no blanks in the column and the lat, lon is properly formed (ie no missing commas,  valid data).

Reply
0 Upvotes
Regular Advisor | Partner

@JAbella are you viewing a page with the query parameters at the end of the url? It looks like it might be empty. e.g. example.com/map?latitude=123&longitude=321

Stefen Phelps, Community Champion, Kelp Web Developer
Reply
0 Upvotes
Highlighted
Regular Contributor

@stefen You are brilliant!  The url isn't empty, but I had included the key and value in the query where it should just be the value. **facepalm**

 

Thank you!!