Nearby people calculation method-----Using MySQL Script calculation method

Source: Internet
Author: User
Tags cos sin

Nearby people calculation method drop  function if exists getdistance;delimiter $$  CREATE definer= ' root ' @ ' localhost ' function ' Getdistance ' (     lon1 float (10,7)     , lat1 float (10,7)    , Lon2 float (10,7)     , Lat2 float (10,7)) RETURNS Doublebegin    declare d double;    declare radius int;    Set radius = 6378140; #如果地球为正球形. The diameter is 6378140 meters    Set d = (2*atan2 (SQRT (SIN (LAT1-LAT2) *pi ()/180/2)           *sin ((LAT1-LAT2) *pi ()/180/2) +           COS ( Lat2*pi ()/180) *cos (Lat1*pi ()/180)           *sin ((lon1-lon2) *pi ()/180/2)           *sin ((lon1-lon2) *pi ()/180/2),           SQRT (1-sin ((LAT1-LAT2) *pi ()/180/2)           *sin ((LAT1-LAT2) *pi ()/180/2)           +cos (Lat2*pi ()/180) *cos (Lat1*pi ()/           *sin ((lon1-lon2) *pi ()/180/2)           *sin ((lon1-lon2) *pi ()/180/2))) *radius;    return d;end$ $DELIMITER; Select Getdistance (116.3899,39.91578,116.3904,39.91576);

Nearby people calculation method-----Using MySQL Script calculation method

Related Article

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.