向地图点添加公里数

发布于 08-29 09:27 字数 661 浏览 8 评论 0原文

早上好。

我想知道如何向地图点(纬度/经度)添加公里数。

例如:南雅拉瓜市的纬度为 -26.462049,经度为 -49.059448。我想要向上、向下和侧面添加 100 公里。我想做一个正方形并得到新的点。

我该怎么做?

我尝试过:

<?php
$distance = 100;
$earthRadius = 6371;
$lat1 = -26.4853239150483;
$lon1 = -49.075927734375;
$bearing = 0;

$lat2 = asin(sin($lat1) * cos($distance / $earthRadius) + cos($lat1) * sin($distance / $earthRadius) * cos($bearing));
$lon2 = $lon1 + atan2(sin($bearing) * sin($distance / $earthRadius) * cos($lat1), cos($distance / $earthRadius) - sin($lat1) * sin($lat2));

echo 'LAT: ' . $lat2 . '<br >';
echo 'LNG: ' . $lon2;
?>

但它返回了错误的坐标。谢谢你!

非常感谢。

Good morning.

I would like to know how do I add kilometers to a map point (latitude / longitude).

For example: The city Jaraguá do Sul is in latitude -26.462049, longitude -49.059448. I want to add 100 kilometers up, down, and on the sides. I want to do a square and get the new points.

How do I do that?

I tried it:

<?php
$distance = 100;
$earthRadius = 6371;
$lat1 = -26.4853239150483;
$lon1 = -49.075927734375;
$bearing = 0;

$lat2 = asin(sin($lat1) * cos($distance / $earthRadius) + cos($lat1) * sin($distance / $earthRadius) * cos($bearing));
$lon2 = $lon1 + atan2(sin($bearing) * sin($distance / $earthRadius) * cos($lat1), cos($distance / $earthRadius) - sin($lat1) * sin($lat2));

echo 'LAT: ' . $lat2 . '<br >';
echo 'LNG: ' . $lon2;
?>

But it's returning wrong cordinates. Thank you!

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城月光淡如水﹏2024-09-05 09:27:05

正如已经指出的那样。 PHP 三角函数以弧度为参数。

参数的度数到弧度的转换就可以了。您可能想要以度为单位的结果,因此使用 rad2deg 转换回来:

<?php
$distance = 100;
$earthRadius = 6371;
$lat1 = deg2rad(-26.4853239150483);
$lon1 = deg2rad(-49.075927734375);
$bearing = deg2rad(0);

$lat2 = asin(sin($lat1) * cos($distance / $earthRadius) + cos($lat1) * sin($distance / $earthRadius) * cos($bearing));
$lon2 = $lon1 + atan2(sin($bearing) * sin($distance / $earthRadius) * cos($lat1), cos($distance / $earthRadius) - sin($lat1) * sin($lat2));

echo 'LAT: ' . rad2deg($lat2) . '<br >';
echo 'LNG: ' . rad2deg($lon2);
?>

as was already pointed out. PHP trigonometric functions take radians as paramters.

degree to radian conversions of the parameters will do the trick. you probably want the result in degrees, so use rad2deg to convert back:

<?php
$distance = 100;
$earthRadius = 6371;
$lat1 = deg2rad(-26.4853239150483);
$lon1 = deg2rad(-49.075927734375);
$bearing = deg2rad(0);

$lat2 = asin(sin($lat1) * cos($distance / $earthRadius) + cos($lat1) * sin($distance / $earthRadius) * cos($bearing));
$lon2 = $lon1 + atan2(sin($bearing) * sin($distance / $earthRadius) * cos($lat1), cos($distance / $earthRadius) - sin($lat1) * sin($lat2));

echo 'LAT: ' . rad2deg($lat2) . '<br >';
echo 'LNG: ' . rad2deg($lon2);
?>
旧话新听2024-09-05 09:27:05

更新:

PHP 三角函数将弧度作为参数,而不是度数,因此您需要使用 deg2rad() 作为参数:

sin(deg2rad($lat))

http://www.php.net/manual/en/function.deg2rad.php


原始答案:

确实是一个大主题。

根据您所需的精度(和覆盖的距离),您可能必须考虑到地球不是一个完美的球体,而是一个大地水准面(扁平的椭球体)。

http://en.wikipedia.org/wiki/Earth_radius

将帮助您开始此操作。

映射和投影是您应该查看的两个主题,也是

来自维基百科的关于距离主题的另一个链接

http ://en.wikipedia.org/wiki/Geographical_distance

UPDATE:

PHP trigonometric functions take radians as Paramters, not degrees, so you need to use deg2rad() as a parameter:

sin(deg2rad($lat))

http://www.php.net/manual/en/function.deg2rad.php


Original answer:

A big Topic indeed.

Depending on your required precision ( and distances covered), you might have to take into account that earth is not a perfect sphere, but a geoid ( a flattened elipsoid).

http://en.wikipedia.org/wiki/Earth_radius

will get you started on this.

Mapping and projection are two topics you should take a look at, too

another link from wikipedia on the topic of distances

http://en.wikipedia.org/wiki/Geographical_distance

眼睛会笑2024-09-05 09:27:05

根据您的新信息,我有两种替代方法。
(1) 谷歌“PHP GIS”。您会发现一些有趣的资源。也许其中一个会起作用。
(2)如果您的企业是通过经纬度来识别的,那么您将不得不使用(1)我认为。但有没有一种“更笨”的方法呢?例如,如果每个企业都链接到一个城市,则使用简单的地图坐标(“K16”)来识别城市。或者一些更智能的代码,但这就是想法。

Based on your new information, I have two alternative approaches.
(1) Google "PHP GIS". You will find some interesting resources. Maybe one will work.
(2) If your enterprises are identified by lat-longitude, then you will have to use (1) I think. But is there a "dumber" approach? For example, if each enterprise is linked to a city, then use simple map coordinates ("K16") to identify cities. Or something a bit smarter code-wise, but that's the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文