Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

MySQL find points within radius from Database

In this article, you will learn how to find points within a radius from provided lat and long by writing a Mysql Query. For example, The SQL statement will find locations that are within a radius of 7 KM to the 22.607672, 88.36853 coordinate.

  • Keep reading on Find nearest location using latitude longitude MySQL

How to get all the results within a radius from provided lat and long from MySql Query

We have stored locations (latitude and longitude) in our database. Find the following query to find the features within the given coordinates and distance using MySQL.

  • Selecting points from a database by latitude/longitude within a bounding circle

SELECT 
  COUNT(*) 
FROM 
  (
    SELECT 
      (
        6371 * ACOS(
          COS(
            RADIANS('22.607672')
          ) * COS(
            RADIANS(Latitude)
          ) * COS(
            RADIANS(Longitude) - RADIANS('88.36853')
          ) + SIN(
            RADIANS('22.607672')
          ) * SIN(
            RADIANS(Latitude)
          )
        )
      ) AS distance 
    FROM 
      bts 
    HAVING 
      distance 
  • Finding points within a radius in MySQL

SELECT 
  Latitude, 
  Longitude 
FROM 
  (
    SELECT 
      Latitude, 
      Longitude, 
      (
        6371 * ACOS(
          COS(
            RADIANS('22.607672')
          ) * COS(
            RADIANS(Latitude)
          ) * COS(
            RADIANS(Longitude) - RADIANS('88.36853')
          ) + SIN(
            RADIANS('22.607672')
          )* SIN(
            RADIANS(Latitude)
          )
        )
      ) AS distance 
    FROM 
      bts 
    HAVING 
      distance 

Download MySQL Query

For more documentation refer to MySQL Docs

Conclusion

I hope you liked this article on how to find points within a radius from MySQL Database. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

The post MySQL find points within radius from Database appeared first on DotNetTec.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

MySQL find points within radius from Database

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×