CMS Development

JAbella
Colaborador

orderBy=geo_distance not ordering by distance

resolver

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!

0 Me gusta
1 Soluciones aceptada
stefen
Solución
Asesor destacado | Partner
Asesor destacado | Partner

orderBy=geo_distance not ordering by distance

resolver

@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

Ver la solución en mensaje original publicado

0 Me gusta
4 Respuestas 4
stefen
Asesor destacado | Partner
Asesor destacado | Partner

orderBy=geo_distance not ordering by distance

resolver

@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
0 Me gusta
JAbella
Colaborador

orderBy=geo_distance not ordering by distance

resolver

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).

0 Me gusta
stefen
Solución
Asesor destacado | Partner
Asesor destacado | Partner

orderBy=geo_distance not ordering by distance

resolver

@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
0 Me gusta
JAbella
Colaborador

orderBy=geo_distance not ordering by distance

resolver

@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!!