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

PHP implements to judge whether employees sign in longitude and latitude within the sign-in.

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "PHP realizes to judge whether employees sign in longitude and latitude". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The specific code is as follows:

/ * calculate the distance between two sets of longitude and latitude coordinates * @ param $lat1 latitude 1 * @ param $lng1 longitude 1 * @ param $lat2 latitude 2 * @ param $lng2 longitude 2 * @ param int $len_type return value type (1murm 2-km) * @ param int $decimal retained decimal places * @ return float * / public function getDistance ($lat1, $lng1, $lat2, $lng2, $len_type = 1 $decimal = 2) {$radLat1 = $lat1 * 3.1415926 / 180.0 $radLat2 = $lat2 * 3.1415926 / 180.0; $a = $radLat1-$radLat2; $b = ($lng1 * 3.1415926 / 180.0)-($lng2 * 3.1415926 / 180.0); $s = 2 * asin (sqrt (pow (sin ($a / 2), 2) + cos ($radLat1) * cos ($radLat2) * pow ($b / 2), 2)); $s = $s * 6378.137; $s = round ($s * 1000) If ($len_type > 1) {$s / = 1000;} return round ($s, $decimal);}

Ps: let's check whether the check-in range is within the specified range based on latitude and longitude.

/ * convert the angle to radians * @ param d Angle * @ return Radians * / private static double rad (double d) {return d * Math.PI / 180.0 } / * first obtain the distance (in meters) by longitude and latitude, and then determine whether a point is in a circular area (according to the given radius) * @ param N1 = > app * @ param N2 = > warehouse * @ param radius * @ return * / public static boolean isInCircle (ZJPoint N1, ZJPoint N2 drawing string radius) {final double EARTH_RADIUS = 6378.137 / Earth radius (km) double radLat1 = rad (n1.getX ()! = null? N1.getX () .doubleValue (): 0); double radLat2 = rad (n2.getX ()! = null? N2.getX () .doubleValue (): 0); double radLon1 = rad (n1.getY ()! = null? N1.getY () .doubleValue (): 0); double radLon2 = rad (n2.getY ()! = null? N2.getY (). DoubleValue (): 0); / / the difference between two points double jdDistance = radLat1-radLat2; double wdDistance = radLon1-radLon2; double distance = 2 * Math.asin (Math.sqrt (Math.pow (Math.sin (jdDistance / 2), 2) + Math.cos (radLat1) * Math.cos (radLat2) * Math.pow (Math.sin (wdDistance / 2), 2)); distance = distance * EARTH_RADIUS; distance = Math.round (distance * 10000d) / 10000d Distance = distance*1000;// converts the calculated distance from kilometers to meters double r = Double.parseDouble (radius); / / to determine whether a point is in a circular area if (distance > r) {return false;} return true;} "PHP to determine whether employees sign in longitude and latitude is within the clock" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Wechat

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

12
Report