Php calculates the distance between two coordinates (longitude, latitude), coordinate longitude _ PHP Tutorial

Source: Internet
Author: User
Php calculates the distance between two coordinates (longitude and latitude). The coordinate longitude is used. Php calculates the distance between two coordinates (longitude and latitude). This article describes how php calculates the distance between two coordinates (longitude and latitude. I would like to share with you how php calculates the distance between two coordinates (longitude and latitude), coordinate longitude

This article describes how php calculates the distance between two coordinates (longitude and latitude. Share it with you for your reference. The details are as follows:

Here, we use php to calculate the distance between two coordinates (longitude, latitude). The Returned result is meter or kilometer.

Function distance ($ lat1, $ lng1, $ lat2, $ lng2, $ miles = true) {$ pi80 = M_PI/180; $ lat1 * = $ pi80; $ lng1 * = $ pi80; $ lat2 X = $ pi80; $ lng2 * = $ pi80; $ r = 6372.797; // mean radius of Earth in km $ dlat = $ lat2-$ lat1; $ dlng = $ lng2-$ lng1; $ a = sin ($ dlat/2) * sin ($ dlat/2) + cos ($ lat1) * cos ($ lat2) * sin ($ dlng/2) * sin ($ dlng/2 ); $ c = 2 * atan2 (sqrt ($ a), sqrt (1-$ a); $ km = $ r * $ c; return ($ miles? ($ Km * 0.621371192): $ km );}

I hope this article will help you with php programming.

The method for calculating the distance between two coordinates (longitude and latitude) in php. Share it with you...

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.