PHP calculates the maximum and minimum longitude and latitude of 4 corners within 3 kilometers of the current coordinates Example_php tips

WBOY
Release: 2016-05-16 19:58:04
Original
2044 people have browsed it

The example in this article describes the PHP method of calculating the maximum and minimum longitude and latitude of four corners within 3 kilometers of the current coordinates. Share it with everyone for your reference, the details are as follows:

//$lng 、$lat 经纬度    
$half = 6371;
    $distance = 3; //3公里 
    $dlng = 2 * asin(sin($distance / (2 * $half)) / cos(deg2rad($lat)));
    $dlng = rad2deg($dlng);
    $dlat = $distance / $half;
    $dlat = rad2deg($dlat);
    $fourpoint = array(
      'left-top' => array('lat' => $lat + $dlat, 'lng' => $lng - $dlng),
      'right-top' => array('lat' => $lat + $dlat, 'lng' => $lng + $dlng),
      'left-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng - $dlng),
      'right-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng + $dlng)
);

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP date and time usage", "PHP object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

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