- 论坛徽章:
- 0
|
- sub distance {
- my ($lat1, $lon1, $lat2, $lon2) = @_;
- my $theta = deg2rad($lon1 - $lon2);
- my $beta = deg2rad($lat2 - $lat1);
- my $dist = 2 * asin(sqrt((sin($beta/2))**2 + cos(deg2rad($lat1))*cos(deg2rad($lat2))*(sin($theta/2)**2))) * $earthRadius *1000;
- return ($dist);
- }
- $px = 119.1991594;
- $py = 34.59840287;
- $shtX = 119.19387;
- $shtY = 34.60185;
- print distance($px, $py, $shtX,$shtY)," Miles\n";
- print distance(34.59840287, 119.1991594, 34.60185, 119.19387) . " Miles\n";
-
复制代码 输出:- 617.851587548396 Miles
- 618.190118611182 Miles
-
复制代码 误差还是蛮大的,应该不是精度的问题吧?
恳请哪位高手赐教! |
|