Java 中的边界框计算
我正在尝试创建一种方法,给定纬度、经度和范围(以英里或公里为单位)返回边界框的东北角和西南角?
我在某处找到了一个函数,但经过一些测试后它似乎不起作用(见下文):
double latrange=range/69.172;
double longrange=Math.abs(range/(Math.cos(inLat) *69.172));
double minlat=inLat-latrange;
double maxlat=inLat+latrange;
double minlon=inLong-longrange;
double maxlon=inLong+longrange;
MapCoord min = new MapCoord(minlat,minlon);
MapCoord max = new MapCoord(maxlat,maxlon);
MapCoord [] rs = new MapCoord[2];
rs[0] = min;
rs[1] = max;
return rs;
I'm trying to create a method that given a latitude and longitude and range (in miles or km) returns the NE and SW corners of a bounding box?
I had a function that I found somewhere but after some testing it doesn't seem to work( see below):
double latrange=range/69.172;
double longrange=Math.abs(range/(Math.cos(inLat) *69.172));
double minlat=inLat-latrange;
double maxlat=inLat+latrange;
double minlon=inLong-longrange;
double maxlon=inLong+longrange;
MapCoord min = new MapCoord(minlat,minlon);
MapCoord max = new MapCoord(maxlat,maxlon);
MapCoord [] rs = new MapCoord[2];
rs[0] = min;
rs[1] = max;
return rs;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不清楚你所说的“不起作用”是什么意思,但从我所看到的代码确实会产生输入的两点 SW 和 NE 。然而,它将突破两极和国际日期变更线。
产生看起来合理的输出的简单测试程序:
Not clear what you mean by "doesn't work" but from what I can see the code does result in two points SW and NE of the input. It will however break close to the poles and the international dateline.
Simple test program that produces reasonable looking output: