A simple algorithm for the distance between MySQL two points

Source: Internet
Author: User

MySQL spatial extension (MySQL spatial Extensions), which allows direct processing, saving, and analysis of geolocation-related information in MySQL, appears to be the "official solution" for using MySQL to process geolocation information. But it is a pity that it does not support some of the most basic geolocation operations, such as querying all data within a radius. It does not even have a distance calculation method between two coordinate points (MySQL spatial's distance method is not supported in the 5.* version)

The official Guide's approach is this:

Glength (LINESTRINGFROMWKB (LineString (Point1, Point2)))

The processing logic of this statement is to first produce a linestring type of data through two points, and then call Glength to get the actual length of the linestring.

This is complicated, seemingly also solves the problem of distance calculation, but readers need to note is: This method calculates the distance of European space, simply speaking, it gives the result is two points in three-dimensional space in the straight line distance, not the plane flying on the Earth's trajectory, but straight through the Earth's straight line.

So if your geo-location information is stored with latitude and longitude, you can't simply use this method to do distance calculation directly.


A simple algorithm for the distance between MySQL two points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.