Home > Backend Development > PHP Tutorial > PHP calculate distance between two GPS points

PHP calculate distance between two GPS points

WBOY
Release: 2016-07-29 09:01:34
Original
1834 people have browsed it

The following is a PHP function to calculate the distance between 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

39.91726

1

2

3

4

5

6

7

8

9

10

11

12

13

#lon is the longitude, lat is the latitude, don’t make a mistake

,$ lat1,$lon2,$lat2){ 2*ATAN2(

SQRT

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

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

/

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

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

)

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

PI

()/180 /2) +COS($lat2*PI()/180 )*COS(

$

lat1*PI()/180)

                                                                        PI()/180 /2) $lon2)*PI ()/180/

2))))*6378140; } Calling method: echo distance(39.91917,116.3896,39.91726,116.3940);1 echo distance(

39.91917,116.3896

,
,116.3940

)

The above introduces PHP to calculate the distance between two GPS points, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template