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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:23:32+00:00 2026-05-26T02:23:32+00:00

I have a table in MySQL db which two of it’s columns are the

  • 0

I have a table in MySQL db which two of it’s columns are the latitude and the longitude of a given geo-point. it’s defined as Float(2,6).
I want to select only the records within a specific radius from a given point.

I found the following code in Java, that checks the distance between to geo-points:

public class Location {

private int latitudeE6;
private int longitudeE6;
    ...
}

public static double CalculateDistance(Location StartP, Location EndP) {

      double lat1 = StartP.getLatitudeE6()/1E6;
      double lat2 = EndP.getLatitudeE6()/1E6; 
      double lon1 = StartP.getLongitudeE6()/1E6;     
      double lon2 = EndP.getLongitudeE6()/1E6;
      double dLat = Math.toRadians(lat2-lat1); 
      double dLon = Math.toRadians(lon2-lon1);   
      double a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
      Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
      Math.sin(dLon/2) * Math.sin(dLon/2); 
      double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
      return earthradius * c;
   }

Currently, I’m doing SELECT without the location, and then I go over the result set and checks if it’s in the radius given. (in Java).
This is surely not the most elegant, efficient way of doing it.
Can you think of a better way ?

  • 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-26T02:23:32+00:00Added an answer on May 26, 2026 at 2:23 am

    Here’s a presentation that describes (I think) how to do what you’re attempting to accomplish in MySQL: Geo/Spatial Search with MySQL

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table which columns are post_id and post_msg. Now I want
I have a MySQL table in which there are two columns , for text
I have a table in mysql which stores (among other columns) a bitmask as
I have a MySQL table which contains the following two fields (There are others,
I have the two columns in my table within Mysql. The Columns are Amount
I have a table called Task which has, among others, two columns: Date_due: a
I have table in MySQL database with two integer columns for example: userid |
I Have MySQL DB table tbl_users , which has two uid , name ,
I have the following problem: In mysql I have a table which contains two
I have a MySQL table with two fields called date and time which are

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.