查找经纬度一定范围内的一组坐标
我正在开发一个涉及 google 地图的 javascript 项目。
目标是从一组经纬度坐标中找出n公里内的16-20个坐标点,使得这16个点如果连接起来将围绕原始坐标形成一个圆圈。
最终目标是做到这一点,这样我就可以找出要在谷歌地图上绘制和连接的坐标,以围绕给定的一组坐标画一个圆圈。
代码将类似于:
var coordinates = Array();
function findCoordinates(lat, long, range) {
}
coordinates = findCoordinates(-20, 40, 3);
现在让神奇的事情发生在 findCooperatives()
函数中。
I am working on a project in javascript involving google maps.
The goal is to figure out 16-20 coordinate points within n kilometers from a set of latitude longitude coordinates such that the 16 points if connected will form a circle around the original coordinates.
The end goal is to make it so I can figure out coordinates to plot and connect on google maps to make a circle around a given set of coordinates.
The code would go something like:
var coordinates = Array();
function findCoordinates(lat, long, range) {
}
coordinates = findCoordinates(-20, 40, 3);
Now to make the magic happen in the findCoordinates()
function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您想要做的是从给定半径的给定点在圆的半径上找到
N
点。一种简单的方法是将圆的 360 度分割成N
个相等的块,并以规则的间隔查找点。以下应该大致完成您想要的操作 -
然后您可以轻松地使用您返回的点数组在谷歌地图上绘制您想要的圆圈。
然而,如果您的总体目标只是围绕一个点以固定半径画一个圆,那么更简单的解决方案可能是使用叠加层。我发现 KMBox 非常容易设置 - 你给它一个中央点、半径和图像覆盖(在您的情况下,是一个边缘周围有可见线的透明圆圈),它负责处理其他所有事情,包括在放大/缩小时调整其大小。
Basically what you're trying to do is find
N
points on the radius of a circle from a given point with a given radius. One simple way of doing it is splitting the 360 degrees of a circle in toN
equal chunks, and finding the points at regular intervals.The following should do roughly what you're after -
The array of points you get back can then easily be used to draw the circle you wish on your google map.
If your overall goal however is just to draw a circle at a fixed radius around a point, then a far easier solution may be to use an overlay. I've found KMBox to be very easy to set up - you give it a central point, a radius and an image overlay (in your case, a transparent circle with a visible line around the edge) and it takes care of everything else, including resizing it on zoom in/out.
不久前我必须找到一些代码来计算大圆距离(如果你不知道我在说什么,只需谷歌“大圆”),我找到了这个网站:
http://williams.best.vwh.net/gccalc.htm
您也许可以构建自己的 JavaScript 代码来执行以下操作使用该站点的 JavaScript 作为参考进行纬度/经度范围计算。在我看来,您只需将 360 度的圆分成相等数量的部分,并在每个“方位”处从中心画一条距离相等的线即可。一旦您知道了每条方位线/距离线另一端的纬度/经度,那么将这些点连接起来形成多边形就很简单了。
I had to find some code to calculate Great Circle distances a while back (just Google "Great Circle" if you don't know what I'm talking about) and I found this site:
http://williams.best.vwh.net/gccalc.htm
You might be able to build up your own JavaScript code to do your lat/lon range calculations using the JavaScript from that site as a reference. It sounds to me like you just need to divide up the 360 degrees of a circle into an equal number of pieces and draw a line out to an equal distance from the center at each "bearing". Once you know the lat/lon at the other end of each bearing/distance line, then connecting the dots to form a polygon is trivial.