Home > Backend Development > PHP Tutorial > PHP calculates the maximum and minimum longitude and latitude of 4 corners within 3 kilometers of the current coordinates Example_php tips

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:58:04
Original
2119 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template