zxhxx 3 years ago
parent
commit
efca1f9d9a
1 changed files with 18 additions and 11 deletions
  1. 18 11
      application/admin/model/institution/Ade.php

+ 18 - 11
application/admin/model/institution/Ade.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\model\institution;
 
+use think\Exception;
 use think\Model;
 
 
@@ -80,17 +81,23 @@ class Ade extends Model
     }
     public static function getDistance($lat1, $lng1, $lat2, $lng2)
     {
-        $earthRadius = 6367000; //approximate radius of earth in meters
-        $lat1 = ($lat1 * pi() ) / 180;
-        $lng1 = ($lng1 * pi() ) / 180;
-        $lat2 = ($lat2 * pi() ) / 180;
-        $lng2 = ($lng2 * pi() ) / 180;
-        $calcLongitude = $lng2 - $lng1;
-        $calcLatitude = $lat2 - $lat1;
-        $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
-        $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
-        $calculatedDistance = $earthRadius * $stepTwo;
-        return round($calculatedDistance);
+        try {
+            $earthRadius = 6367000; //approximate radius of earth in meters
+            $lat1 = ($lat1 * pi()) / 180;
+            $lng1 = ($lng1 * pi()) / 180;
+            $lat2 = ($lat2 * pi()) / 180;
+            $lng2 = ($lng2 * pi()) / 180;
+            $calcLongitude = $lng2 - $lng1;
+            $calcLatitude = $lat2 - $lat1;
+            $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
+            $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
+            $calculatedDistance = $earthRadius * $stepTwo;
+            return round($calculatedDistance);
+        }catch (Exception $exception)
+        {
+            @file_put_contents("getDistance.txt",$lat2.'--'.$lng2);
+            return 0;
+        }
     }