Sorting by position

Viewing 3 reply threads
  • Author
    Posts
  • March 24, 2019 at 11:47 AM #34094

    Antonio Calanducci
    Participant

    Hello,

    I am a new Tap Forms users, moving my first steps using this great app.
    My first form collects a set of places, and I have a field of type position.
    I have configured the form to be sorted by position, but I see it uses an alphabetical order on the addresses in the field. I would like instead to order the records by distance from my current position. I guess you save internally the lat and long, so using the current position it should be possibile to sort by distance. Is there any configuration I am missing to set this behaviour?

    thanks a lot
    Antonio

    March 25, 2019 at 1:24 PM #34098

    Brendan
    Keymaster

    Hi Antonio,

    I don’t have a function in Tap Forms to sort by distance based on the latitude and longitude values in a Location field. Unless of course you have your own separate distance function.

    So you’re not missing anything at the moment.

    Since distance can change depending on where you are and the indexes used for sorting are based on field values, I’d have to write some routine to loop through all the records and write into a distance field which could then be sorted by. It would possibly make that form’s records take more time to load in every time though. I’ll think about it for a future update perhaps.

    Thanks,

    Brendan

    March 25, 2019 at 2:15 PM #34099

    Antonio Calanducci
    Participant

    Hi Brendan,

    thank you for the reply.
    What type of database are you using behind the scene to store data locally? As I see you support CouchDB syncing, this let me think that you could use Couchbase mobile, that should support geospatial queries. But as you are mentioning indexes in your answer maybe it’s not the case (I read somewhere you used to use SQLite, but not sure if this applies to the macOS version too).

    I haven’t yet taken a look to the Javascript APIs: is there some hook to run a script at a given time? For example, if I can set a trigger on form loading, I could run a script that takes my current position, calculate the difference between my position and every fields’s position and populate a distance field, so I can sort the records by this field. Is this what you meant above as “separate distance function” ?

    I know this is not optimal, but at least I could solve my problem for the moment.
    thank you

    March 25, 2019 at 11:44 PM #34102

    Brendan
    Keymaster

    Hi Antonio,

    Yes, I do use CouchbaseLite for Tap Forms. And yes you’re right, they do have geo spatial queries. In fact, the Mac version uses that on the Map View to fetch records that are within a certain geographic area as defined by the zoom level of the map. But it still fetches the records according to the defined Sort Field settings, not by distance to some arbitrary coordinate.

    There’s no auto-run function for scripts outside of a Field script that gets run when you modify a field that the script references. You can setup a shortcut key to run a Form Script though. You would have to manually trigger that when you select the form. You can also add a Run Script button to a custom layout to run a script too.

    You might be able to write some JavaScript to call out to a web service to figure out the distance between two points and then update a distance field within Tap Forms and then sort by that. Either that or if there’s a distance algorithm in JavaScript you could use, such as the Levenshtein distance algorithm. But that only gives you the distance between two points ‘as the crow flies’.

Viewing 3 reply threads

You must be logged in to reply to this topic.