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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:01:29+00:00 2026-06-04T23:01:29+00:00

I have a database with a few thousand positions. These are busstops. What I

  • 0

I have a database with a few thousand positions. These are busstops. What I would like to do is to get the X amount of nearest values to an LON/LAT position.

This is the layout of my table:

CREATE TABLE IF NOT EXISTS `buss_StopPoints` (
  `Name` varchar(50) NOT NULL,
  `LocationNorthing` varchar(30) NOT NULL,
  `LocationEasting` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

These are some example rows:

INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station', '59.3195952318672', '18.0717401337168');
INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 2', '59.3195772927918', '18.0717389396547');
INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 3', '59.3234014331742', '18.0671617033088');
INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 4', '59.3233921590479', '18.0671786573678');
INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 5', '59.3313179695727', '18.061677395945');

My question: How can I make a select statement that selects the nearest X amount of rows from the DB, both in negative and positive direction. (e.g. lets say I ask for 59.3234014331742,18.0671617033088 and want the nearest 4 stations, which is this case should return all).

  • 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-04T23:01:31+00:00Added an answer on June 4, 2026 at 11:01 pm
    LAT = latitude value
    LON = longitude value
    
    SELECT Name, (6371 * acos( cos( radians(LAT) ) * cos( radians( LocationNorthing ) ) * cos( radians( LON ) - radians(LocationEasting) ) + sin( radians(LAT) ) * sin( radians(LocationNorthing) ) )) AS distance order by distance
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few thousand strings ( items ) that I would like to
I have a database that has a few unknown months or days formatted like
I have a database table with a few thousand entries. A part of the
So I have a few thousand articles indexed in my database, I want to
I have a jqgrid where the database table has a few thousand rows, but
I have a database with few tables, ex.: Employee (Id, Name, state, country) Material
I have quite a few situations where I have database structures similar to: TABLE
So I have a database with a few tables. The first table contains the
I have local database driven website which contains a few sequences which are uniquely
I have a MySQl database with a few tables, all UTF-8 and MyISAM storage.

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.