How to filter model by distance

edited July 23, 2019 in Ideas
Is it possible to create a filter condition that limits records based on distance. For example if have a custom Geocode field on Contact named Location__c I would like the filter to result in a SOQL query like SELECT Id FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION(latitude,longitude), 'mi') < miles Ideally I would also like the values for latitude, longitude and miles be fitlerable. I'd like to combine this so that geocoordinates from my position or clicking a certain position on a map limits the model results.
3
3 votes

Implemented Β· Last Updated

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN πŸ’ŽπŸ’ŽπŸ’Ž
    edited March 2, 2017
    Peter, i'm sure you've already come to this conclusion, but there's really no way to achieve this with Skuid Models at present. I'm changing this to an Idea, and i'm voting it up, because it would be pretty useful, I agree.
  • edited March 2, 2017
    Zach, I was guessing this but wouldn't have been surprised if you had a simple solution that I did not think of. A usable workaround for us will be to simply filter on the Latitude and Longitude fields min and max values and that will return all records within that square. Not as elegant as a simple distance filter but usable when we need to limit a large model so that only the most nearby records are shown. Since we are using this withiin a limited geographic area just using a fixed decimal value for distance per degree will work ok. So based on the current postiion we would click the map, get the current coordinates, calculate max and min values by adding, removing a constant and update 4 filters on the model and refresh and that should give us all records close enough to be within that square. I tried the filters out and it seems to work ok.
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN πŸ’ŽπŸ’ŽπŸ’Ž
    edited December 21, 2016
    Your approach makes sense, good workaround.
  • edited December 4, 2017
    Hi Peter, just wondering if you got any further with this, and if so, what the approach was? We are looking to implement something similar, but definitely need the 'radius' search, to return all records within XX Miles/km of a user-selected location (which has its own lat/long coords).

    Thanks, Greg
  • edited January 14, 2015
    We also have this need (to search on radius based on geolocation). Β Up vote here!
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN πŸ’ŽπŸ’ŽπŸ’Ž
    edited December 22, 2018
    The ability to perform Distance / Radius search based on Geolocation / Address fields has been added with Skuid Banzai! When you add a Condition to a Geolocation or Address type field, the SOQL DISTANCE() function will automatically be applied to the field, and you'll see new options for determining the source of the value to use for the kilometer / mile radius value.
  • edited July 23, 2019
    This is awesome. Really awesome. I think it's lost some attention being just one of the long list of features being released in Banzai, but I think there's some huge potential in this. Thanks Skuid Team, you guys rock!.
  • edited July 23, 2019
    So how would you order for the closest three locations in an object?

    like:Β Β ORDER BY DISTANCE(GeoC__c, GEOLOCATION(22.5697,

    88.3697) , 'mi')Β  like you do can in SOQL?

    ideally GEOLOCATION() parameters should come from another model as well.
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN πŸ’ŽπŸ’ŽπŸ’Ž
    edited July 23, 2019
    This is not possible right now, but it's a great point! It definitely makes sense that you'd want to be able to order the results by distance from either the user's current location, or distance from a LOCATION or ADDRESS field in another Model. Could you post this as a new Idea, so that others can "Me Too!" it and express their desire for this as well?Β 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!