PHP calculates the distance between two GPS points

Source: Internet
Author: User
: This article describes how to calculate the distance between two GPS points in PHP. For more information about PHP tutorials, see. The following is a function for PHP to calculate the distance between two GPS points:

PHP calculates the distance between two GPS points
Distance between two GPS coordinates calculated by Mysql
Javascript calculates the distance between two GPS points

# When lon is Longitude and lat is latitude, do not mistake function distance ($ lon1, $ lat1, $ lon2, $ lat2) {return (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 ()/180) * SIN ($ lon1-$ lon2) * PI ()/180/2) * SIN ($ lon1-$ lon2) * PI ()/180/2) * 6378140 ;}

1

2

3

4

5

6

7

8

9

10

11

12

13

# When lon is Longitude and lat is latitude, do not make a mistake.

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

Return (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 ()/180)

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

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

}

Call method:

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

1

Echodistance (39.91917, 116.3896, 39.91726, 116.3940 );

The preceding section describes the distance between two GPS points in PHP computing, including the following content. I hope my friends who are interested in the PHP Tutorial will be 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.