Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: algorithm

  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts


    good morning.
    i am soliman muttawa
    the case is as follows:
    i have my database which contains names, address, and 2-d coordinate (x,y)
    and what i want is that when the user checks in his coordinates it ll be sent to the database and compared and then it send back the following

    a list of the distance between the user and the stores ( lets say the nearest 10 or what ever) in ascending order .

    to sum up i want an algorithm that measure distance between 2d coordinates and sort them in ascending order based on distance and if u can send me as a source code or pasudeo code it ll be more than great

    thanks alot for your help
    appricate it

    and dont worry it is not an assignment or anything like this only for me personal use and knowledge i am political science student and i am graduated 2 years ago
    i researched :
    1 )bird's eye view ( wont work 3d coordinates)
    2) haversine ( didnt get it )
    what i though of to do normal euclidean or manhathan to get the distance then a kind of sorting .. thank you again

  2. AdSlot6
  3. #2
    New to the CF scene
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts
    and i though of knn ( k nearestneighbor

  4. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,945 Times in 4,906 Posts
    Take a look here:
    Look at the first DEMO there.

    That code is very efficient. It does *NOT* use the haversine formula, but it is accurate to within perhaps 100 meters for distances up to 200 km. If that is good enough for you, then you don't need to use haversine formula.
    Be yourself. No one else is as qualified.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts