PHP calculates the distance between two GPS points

Source: Internet
Author: User
Tags cos sin

Here is the function of PHP to calculate the distance of two GPS points:

PHP calculates the distance between two GPS points
MySQL calculates the distance between two GPS coordinates
JavaScript calculates the distance between two GPS points

#lon为经度, lat is latitude, must not be mistaken Oh function <span>distance</span> ($lon 1, $lat 1, $lon 2, $lat 2) {return (2*atan2 (SQRT (SIN (($lat 1-$lat 2) *pi ()/180/2) *sin (($lat 1-$lat 2) *pi ()/180/2) + COS ($lat 2*pi ()/180) *cos ($lat 1*pi ()/180) *sin (($lon 1-$lon 2) *pi ()/180/2) *sin (($lon 1-$lon 2) *pi ()/180/2), SQRT (1-sin (($lat 1-$lat 2) *pi ()/180/2) *sin (($lat 1-$lat 2) *pi ()/180/2) +cos ($lat 2*pi ()/180) *cos ($lat 1*pi ()/180) *sin (($lon 1-$lon 2) *pi ()/180/2 ) *sin (($lon 1-$lon 2) *pi ()/180/2)))) *6378140; }

1

2

3

4

5

6

7

8

9

10

11

12

13

#lon为经度, Lat is the latitude, must not be mistaken oh

functiondistance($lon1,$lat1 ,$lon2,$lat2){

return(2*ATAN2(SQRT (SIN($lat1-$lat2 )*PI() / 2)

*SIN($lat1-$lat2 )*PI()/2 )+

COS($lat2*PI()/ *COS($lat1*PI) ()/+)

*SIN($lon1-$ lon2)*PI()/ / 2 )

*SIN($lon1-$lon2 )*PI()/2 )),

SQRT(1-SIN($ lat1-$lat2)*PI( )/2)

*SIN($lat1-$ lat2)*PI()/ / 2 )

+COS($lat2*PI()/ the )*COS($lat1*PI() /+)

*SIN($lon1-$ lon2)*PI()/ / 2 )

*SIN($lon1-$lon2 )*PI()/2 )))*6378140;

}

Call Method:

echo distance (39.91917,116.3896,39.91726,116.3940);

1

Echo Distance (39.91917,116.3896,39.91726, 116.3940);

The above describes the PHP calculation of the distance between two GPS points, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.