谷歌地图折线:从原点计算端点

发布于 2024-10-19 06:16:46 字数 216 浏览 2 评论 0原文

我想使用 Google 地图绘制折线。
我已经阅读了 API 并做了一些研究,但我仍然有一个基本问题。

信息:

lat: 63.43243500
lon: 10.37045667
angle: 230 degrees (0 = north)

我如何制作一条 60 米长、源自原始纬度/经度、角度为 230 度的折线?

I want to draw a polyline using Google Maps.
I have read the API and did some research, but i am still left with a fundamental question.

Information:

lat: 63.43243500
lon: 10.37045667
angle: 230 degrees (0 = north)

How can i make a polyline that is 60 meters long that originates from the original lat / lon with a angle of 230 degrees?

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

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

发布评论

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

评论(1

心头的小情儿 2024-10-26 06:16:46

您需要计算直线的端点(纬度,经度)。这可以使用 google.maps.geometry.spherical 命名空间。它具有三个必需参数:起始纬度/经度点、行驶距离和航向角。

以下是适合您情况的示例:

var startLL = new google.maps.LatLng(63.43243500,10.37045667);
var endLL = new google.maps.geometry.spherical.computeOffset(startLL, 60, 230);

来自折线示例 ,您可以从这些点创建多段线,如下所示:

var coordinates = [startLL, endLL];
var path = new google.maps.Polyline({
  path: coordinates,
  strokeColor: "#FF0000",
  strokeOpacity: 1.0,
  strokeWeight: 2
});

更新: 您还需要确保包含 geometry 库,默认情况下不包含该库。按照此处的说明操作,您需要更改引导程序请求:

http://maps.google.com/maps/api/js?libraries=geometry&sensor=false

You need to calculate the endpoint of the line in (lat,lon). This can be done using the calculateOffset function in the google.maps.geometry.spherical namespace. It has three required parameters: the starting lat/lng point, the distance to travel, and the heading angle.

Here's an example for your situation:

var startLL = new google.maps.LatLng(63.43243500,10.37045667);
var endLL = new google.maps.geometry.spherical.computeOffset(startLL, 60, 230);

From the Polyline example, you can create a Polyline from these points as:

var coordinates = [startLL, endLL];
var path = new google.maps.Polyline({
  path: coordinates,
  strokeColor: "#FF0000",
  strokeOpacity: 1.0,
  strokeWeight: 2
});

Update: You also need to make sure that you include the geometry library, which is not included by default. Following the instructions here, you need to change your bootstrap request to:

http://maps.google.com/maps/api/js?libraries=geometry&sensor=false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文