Getting Started

Find the nearest Starbucks using QuickBase

  • 1.  Find the nearest Starbucks using QuickBase

    Posted 02-24-2020 18:32
    Last week Howard popped into an "Office Hours" webinar asking about how to find the closest customers to a given Latitude and Longitude location.  Well you can do that with QuickBase.

    I went looking for a CSV file with a bunch of Latitude and Longitude locations and I found a file with all the Starbucks locations in the US.

    The essence of the application is to find a Starbucks, enter the distance you want to search and return a report and map of all those locations within that distance.  This can be calculated if you have both the Home and the Destination's Latitude and Longitude.


    So we now have a Locations table butktrachy@quickbase.com we need to add a parent table we can use to pass down all the home's Latitude, Longitude and Distance as lookup fields.

    We add the "Common Parent" table with only one record and made that related to all Location records. (we changed the reference field, "Related Common Parent" to a formula numeric field and put the number 1 in as a formula.  Since there was only one Common Parent record, it's Record ID# was 1.  

    So we created an automation that fires whenever a Location record's "Within Miles" field is updated.  The automation will edit the parent record and update its Latitude, Longitude and Within Miles fields.  This constant one to ALL relationship between the tables allowed us to always be sharing the last requested Latitude, Longitude and Mileage.

    Trigger:
    This shows the trigger part of the automation.

    Action:
    This is the second half of the automation that updates the Common Parent table.

    Now that all the data is on all the location records, we added a formula numeric field to calculate the distance between the two.

    var number HomeLat = ToNumber([Home Latitude]);
    var number HomeLong = ToNumber([Home Longitude]);
    var number Lat = ToNumber([Destination Latitude]);
    var number Long = ToNumber([Destination Longitude]);
    var number Distance = Round(((69*($HomeLat - $Lat))^2 + (53*($HomeLong - $Long))^2)^0.5);
    
    If($HomeLat = 0 or $Lat= 0 , 0 , $Distance)
    

    Next we needed a way to flag only those locations that were within the "Within Miles" range.  We created a formula checkbox field that would be checked if the Location record was within the range.

    Is only checked if the distance is equal to or less than the Distance Mileage.

    So now we have the matching criteria to create the report link fields to display the results.  

    Report Link configuration

    The result:


    We cover topics like this in our daily, "Office Hours" webinars.  Held M-F at 1:00 PM Eastern time.  Feel free to drop in anytime.


    ------------------------------
    Kirk Trachy , Senior Solutions Consultant
    QuickBase | 603-674-5454 M | ktrachy@quickbase.com
    ------------------------------