Skip to main content

Find points(latitude/longitude) within a distance using MySQL

Free Teachnology provide free php,mysql,jquery,javascript,

MySQL - when you calculate distance between latitude/longitude its simple way :

Step : 1 
create table as per your requirement and two column  latitude/longitude with data type Double



Range
On a client project recently, we had to make it easy to filter database query results based on the distance between a user and an entity in our database. It's easy to get overwhelmed in that context, worrying about the crazy amount of PHP calculations you're going to have to run.

MySQL can do that! If you need to calculate this, you can actually get far by just using MySQL!
MySQL 5.7 introduced latitude, which is a native function to calculate the distance between two points.

That’s an interesting start but it doesn’t apply with Geography since the distance between lines of latitude and longitude are not an equal distance apart. As you get closer to the equator,
lines of latitude get further apart. If you use some kind of simple triangulation equation, it may measure distance accurately in one location and terribly wrong in the other,
because of the curvature of the Earth.


Code :

Its very simple to calculate distance between two place  using latitude and logitude

MYSQL :



SELECT *,((((acos(sin((10.568047*pi()/180)) * sin((latitude*pi()/180))+cos((10.568047*pi()/180)) * cos((latitude*pi()/180)) * cos(((73.8773632- longitude)*pi()/180))))*180/pi())*60*1.1515*1.609344)) as distance FROM `table_name` HAVING distance<='3'


Where condition put as per your table outpout requirment, 10.568047 this is latitude of first column,longitude is 73.8773632 its same place you can put from is table name and having coluse mention that alise varaible value
if you want 3 kilometer then i can put 3 if you want 7KM then put 7

Conclusion :

If you're working in MySQL 5.7+ and provideds find a distances,ways to query aganist,its real world distance.

if you have query let me feedback on mail id : disuzajen@gmail.com


Comments

Popular posts from this blog

using PDO database connection add,update,delete,edit operation

PDO advantage : 1-Object Oriented 2-Bind parameters in statements (security) 3-Allows for prepared statements and rollback functionality (consistency) 4-Throws catcheable exceptions for better error handling (quality) 5-Exception mode; no need to check error state after each API call. It's best to tell PDO how you'd like the data to be fetched. You have the following options: 1-PDO::FETCH_ASSOC: returns an array indexed by column name. 2-PDO::FETCH_BOTH: (default):returns an array indexed by both column name and number. 3-PDO::FETCH_BOUND:Assigns the values of your columns to the variables set with the ->bindColumn() method. 4-PDO::FETCH_CLASS: Assigns the values of your columns to properties of the named class. It will create the properties if matching properties do not exist. 5-PDO::FETCH_INTO:Updates an existing instance of the named class. 6-PDO::FETCH_LAZY: Combines. 7-PDO::FETCH_BOTH/PDO:FETCH_OBJ, creating the object variable names as t...

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links user want to share any information then use following code  and read step by step Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links if you want share profile on following social link : 1-Facebook 2-twitter.com 3-LinkedIn 4-google +, Code link : https://drive.google.com/open?id=1IzTZZh_0euDqFSHL_vPRiQePlNTw3h-q Demo link : http://freeteachnology.hol.es/socialshare/ To modify a page's thumbnail image, description, and additional metadata for these services, you can provide meta tags in the HTML code of the page.Implementing Open Graph Meta Tags You can implement meta tags in a number of ways. In content management systems might  be allow you to modify a page's meta tags , then use following code in meta section of your project code, <link href="bootstrap.min.css" rel="stylesheet"> <link href="bootstrap-tour.m...

GUID for globally unique identifier

How to create GUID in php 1-guid stands for globally unique identifier generally used to create random unique strings in php, create access token in php 2-Mostly use of GUID for generating access token, generate unique id, generating unique string in php. Using this article how to create guide in php you can create a random string for any use to keep unique 3-GUID consists of alphanumeric characters only and is grouped in five groups separated by hyphens as seen in this example: 3F2504E0-4F89-11D3-9A0C-0305E82C3301 Eg:- <?php /** * Generate Globally Unique Identifier (GUID) * E.g. 2EF40F5A-ADE8-5AE3-2491-85CA5CBD6EA7 * * @param boolean $include_braces Set to true if the final guid needs * to be wrapped in curly braces * @return string */ function generateGuid($include_braces = false) { if (function_exists('com_create_guid')) { if ($include_braces === true) { return com_create_guid(); } else { return substr(com_cr...