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 8520487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:33:01+00:00 2026-06-11T06:33:01+00:00

I have been searching quite a bit for an answer, but maybe I’m just

  • 0

I have been searching quite a bit for an answer, but maybe I’m just not using the correct terminology. I am creating an app that will access a database to return a list of other users that are within a certain distance of the users location. I’ve never worked with this type of data, and I don’t really know what the values mean. I’d like to do all the calculations on the backend with either MySQL or PHP. Currently, I am storing the latitude and longitude as doubles within the database. I can access them and store them, but I have no idea how I might be able to sort them based on distance. Perhaps I should be using a different type or some technique that is common in this area. TIA.

  • 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-06-11T06:33:02+00:00Added an answer on June 11, 2026 at 6:33 am

    It sounds like you need to use the haversine formula which gets the distance between two sets of long/lat coordindates (adjusting for curvature of the earth).

    If you run a query with that as an output, you can easily sort them based on minimum distance from the user.

    Here is a link to implementing the haversine in 9 commonly used languages and here is a SO question which implements it inside a SQL query.

    Here is the query that you could adapt (gets anything within 25 miles ordered from closest to furthest):

    SELECT 
        id, 
        ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance 
    FROM 
        markers 
    HAVING 
        distance < 25 
    ORDER BY 
        distance 
    LIMIT 
        0 , 20;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching for quite a bit now but I have never been
I've been searching quite a bit now but cannot find the answer to this.
I have been searching this for quite sometime but could not find an appropriate
I have been searching for an answer during quite a long time before coming
I have been searching for quite a while now but i am unable to
I know this is a popular topic, but I've been searching quite a bit
I have been searching for an answer for quite some time, and I have
I've been doing quite a bit of searching, but haven't been able to find
I have been searching this for quite a while but couldn't find a solution
I have been searching the web for an answer now for quite a while,

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.