地理圆到矩形坐标 [英] Geo circle to rectangle coordinates
问题描述
鉴于输入,中心纬度,中心经度和半径(以公里为单位),我想获取包含该圆的矩形的坐标(东北和西南纬度/经度).
Given the input, center latitude, center longitude and radius in kilometers, I want to get the coordinates for the rectangle that contains this circle (northeast and southwest lat/lng).
我应该自己编写方法吗?尽管我担心数学有些生疏,但我还是担心不去解释某些事情.还是可以找到适用于Java的现成实现?我的项目中有google maps sdk,但在那里找不到任何有用的东西.
Should I write the method myself? Even though I'm afraid not to account for some things as my math is rusty. Or can I find a ready implementation for java? I have google maps sdk in my project but I couldn't find anything useful there.
推荐答案
我认为您的平方半径比地球半径(6371 km)小得多 这样您就可以安全地忽略地球的曲率.
I suppose your square radius is much smaller than the earth's radius (6371 km) so that you can safely ignore the earth's curvature.
那数学很简单:
// center of square
double latitudeCenter = ...; // in degrees
double longitudeCenter = ...; // in degrees
double radius = ...; // in km
double RADIUS_EARTH = 6371; // in km
// north-east corner of square
double latitudeNE = latitudeCenter + Math.toDegrees(radius / RADIUS_EARTH);
double longitudeNE = longitudeCenter + Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(latitudeCenter)));
// south-west corner of square
double latitudeSW = latitudeCenter - Math.toDegrees(radius / RADIUS_EARTH);
double longitudeSW = longitudeCenter - Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(latitudeCenter)));
示例:
中心(lat,lon)在48.00,11.00
和半径10
km
将在48.09,11.13
给出NE-corner(lat,lon),在47.91,10.87
给出SW-corner(lat,lon).
Center(lat,lon) at 48.00,11.00
and radius 10
km
will give NE-corner(lat,lon) at 48.09,11.13
and SW-corner(lat,lon) at 47.91,10.87
.
这是使用 <google-maps-services-java
API的c5> :
And here is how to do it with LatLng
and Bounds
of the google-maps-services-java
API:
public static final double RADIUS_EARTH = 6371;
public static Bounds boundsOfCircle(LatLng center, double radius) {
Bounds bounds = new Bounds();
double deltaLat = Math.toDegrees(radius / RADIUS_EARTH);
double deltaLng = Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(center.lat)));
bounds.northeast = new LatLng(center.lat + deltaLat, center.lng + deltaLng);
bounds.southwest = new LatLng(center.lat - deltaLat, center.lng - deltaLng);
return bounds;
}
这篇关于地理圆到矩形坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!