Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:34:16+00:00 2026-05-31T11:34:16+00:00

I am putting together a store finder which works on a radius from a

  • 0

I am putting together a store finder which works on a radius from a postal code. I have done this many times using standard Queries and QoQs, but now trying to put one together using cf9 ORM… but seemed to have reached the limit of my capabilities with the last bit.

I am pulling out an entity and processing it. At the end, I need to:

a. Remove a record if it doesn’t meet a certain criteria (distance is greater than specified by user)

OR b. Add a new property to the record to store the distance.

So at the end, all I want in my entity are those stores that are within the range specified by the user, with each record containing the calculated distance.

Best way to see what I am trying to do is to view the full function

Any suggestions greatly appreciated!!

public function getByPostcodeRadius(required postcode="", 
                                        required radius=""){

        //set some initial vals
        rs = {};
        geo = New _com.util.geo().init(); 
        local.postcodeGeo = geo.getGeoCode("#arguments.postcode#, Australia");
        local.nearbyStores = "";
        local.returnStores = {};

        //load stores
        local.stores = entityload("stores");

        //loop over all stores and return list of stores inside radius
        for(i=1; i <= ArrayLen(local.stores); i++){

            store = {};
            store.id = local.stores[i].getID();
            store.geoCode = local.stores[i].getGeoCode();
            store.Lat = ListgetAt(store.geoCode,1);
            store.Lng = ListgetAt(store.geoCode,2);

            distance = geo.getDistanceByGeocode(local.postcodeGeo.Lat,local.postcodeGeo.Lng,store.Lat,store.Lng);


            //************************
            //HERE IS WHERE I AM STUCK.

            if (distance LT arguments.radius){

                //here I need to add a property 'distance' and set it's value
                local.stores[i].distance = distance; // this adds it to the object, but not with the PROPERTIES

            } else {

                // here i need to remove the store from the object as it's distance was greater than the one passed in
                arrayDeleteAt(local.stores,i); //this clearly isn't working, as positions are changing with each loop over

            }

        }

        return local.stores;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:34:17+00:00Added an answer on May 31, 2026 at 11:34 am

    I’d approach this from a different angle:

    1) Instead of deleting from the array of all stores those that don’t match, I’d build an array of those that do and return that.

    2) If the distance is specific to each query and not a property of the store object, then I wouldn’t try adding it to the store, but just “associate” it with the specific data I’m returning for this search.

    Putting to the 2 together, I’d return an array of structs containing the store object and its distance from the requested postcode. (You could just return a single struct of the store object and distance, with the store ID as key, but I prefer working with arrays.)

    Here’s how I’d code it (not tested because I don’t have your geo class or entity code):

    public array function getByPostcodeRadius(required postcode="", required radius=""){
    hint="I return an array of structs each containing a store object within the requested radius and its distance from the requested post code"
    // Geo settings
    local.geo = New _com.util.geo().init(); 
    local.postcodeGeo = local.geo.getGeoCode("#arguments.postcode#, Australia");
    // initialise the array of structs to return, which will contain stores within the requested radius and their distance from the postcode
    local.nearbyStores = [];
    //load all stores
    local.stores = entityload("stores");
    //loop over all stores and add those inside the radius to the return array with their distance
    for( var storeObject in local.stores ){
        // determine the lat-lng for this store
        local.storeLat = ListgetAt(storeObject.getGeoCode(),1);
        local.storeLng = ListgetAt(storeObject.getGeoCode(),2);
        // get the distance from the requested postcode
        local.distance = local.geo.getDistanceByGeocode(local.postcodeGeo.Lat,local.postcodeGeo.Lng,local.storeLat,local.storeLong);
        if (local.distance LT arguments.radius){
            // create a struct of the store object and its distance and add to the nearby stores array
            local.thisStore =   {
                store   =   storeObject
                ,distance   =   local.distance
            };
            ArrayAppend( local.nearbyStores,local.thisStore );
        }
    }
    return local.nearbyStores;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with putting this query together. I'm using Mysql I have two
I am putting together a backbone example in which models are created edited and
I'm putting together a JavaScript object called ListBox which takes a two-dimensional array, and
For putting together a site from scratch, what are the advantages and disadvantages of
I am putting together a Flash game (using Flixel) and I have a lot
Okay, so I'm putting together a book store with Ruby on Rails. Books are
i'd appreciate some help putting together a sql script to copy data from one
I am putting together an old post here with this new one. My main
I have a .jar file I'm putting together. I want to create a really
I'm putting together a sprite and have two questions. Something I've always wondered whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.