• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jul 23rd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. <?php
2.
3. namespace App\Services\Coordinates;
4.
5. class CoordinateService
6. {
7.     /**
8.      * Computes the distance between two coordinates.
9.      *
10.      * Implementation based on reverse engineering of
12.      *
13.      * @param float \$lat1   latitude from the first point
14.      * @param float \$lng1   longitude from the first point
15.      * @param float \$lat2   latitude from the second point
16.      * @param float \$lng2   longitude from the second point
18.      *
19.      * @return float distance in meters
20.      */
21.     public function computeDistance(\$lat1, \$lng1, \$lat2, \$lng2, \$radius = 6378137)
22.     {
23.         static \$x = M_PI / 180;
24.         \$lat1 *= \$x;
25.         \$lng1 *= \$x;
26.         \$lat2 *= \$x;
27.         \$lng2 *= \$x;
28.         \$distance = 2 * asin(sqrt(pow(sin((\$lat1 - \$lat2) / 2), 2) + cos(\$lat1)
29.         * cos(\$lat2) * pow(sin((\$lng1 - \$lng2) / 2), 2)));
30.
32.     }
33.
34.     /*
35.      * Algorithm based on the spherical law of cosines.
37.      *
38.      *To count in miles change 6371 to 3959
39.      */
41.     {
42.         return '*,
43.                (
44.                    6371 *