Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to calculate the distance between two coordinates by php

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces php how to calculate the distance between the two coordinates, the article is very detailed, has a certain reference value, interested friends must read it!

The details are as follows:

Here, php is used to calculate the distance between two coordinates (longitude, latitude), and the return result is meters or kilometers.

Function distance ($lat1, $lng1, $lat2, $lng2, $miles = true) {$pi80 = M_PI / 180; $lat1 * = $pi80; $lng1 * = $pi80; $lat2 * = $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 * dlng/2 (atan2 ($a), atan2 (1-$a) $km = $r * $c; return ($miles? ($km * 0.621371192): $km);} above is all the content of the article "how php calculates the distance between two coordinates". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How does JavaScript realize that the script never goes wrong

    This article is about how JavaScript makes scripts error-free. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look. Scripts never go wrong

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report