Bug / Feature Request - Sorting by Geo Address

My application has a search for items in my database that contain a geographic address, with the search criteria seeking data records within X miles of a location. The search works as designed, but I would also like to sort the results by their distance to the specific location (see search below). When I create this search, the results are not sorted by distance (its unclear what order they are returned by). Is the ‘sort by’ supposed to sort by distance, or it there another way to accomplish this sorting mechanism?

I posted a response but deleted it because I didn’t think it would help after all.

Question: what is the custom state “closestTerritories”? Like, what datatype is it?

This is a custom Data Type in my database. Basically it just has a few data fields:

  • Name (text)
  • Price (number)
  • geoAddress (geographic address)

My “search for” is a search for this closestTerritories datatype, and ultimately I want the results sorted by distance from the provided zip. Does that make sense?

I think I found your problem.

I was able to pretty much duplicate what you’re trying to do on a page I’m working on right now.

I was able to get it to work just fine with everything you did…almost.

Your problem is the zip code you’re getting from the page url. For the distance to be calculated, it looks like it needs BOTH values to be valid geoaddresses.

If you go into your search and key in your zip code, you’ll see that it converts it to a geoaddress. For example, I keyed in the value “10010” in the “Distance from” field and it converted it to a valid geoaddress:

So I am guessing (repeat: GUESSING) that you can’t just pass it a zip code.

Hmmmm…

Right now, you’re probably getting the value from the URL as follows:

Try this instead:

This should convert “10010” to a geoaddress. Then THAT can be used in your search with no further changes.

I think. Sorry, but hope it works.

Ah yes, right you are! Thanks for much for your help!

Good news!

And I even learned a bit figuring this out, too!

This topic was automatically closed after 14 days. New replies are no longer allowed.