地理圆到矩形坐标
Geo circle to rectangle coordinates
给定输入、中心纬度、中心经度和以公里为单位的半径,我想获得包含此圆的矩形的坐标(东北和西南 lat/lng)。
我应该自己写方法吗?尽管我害怕不考虑某些事情,因为我的数学生锈了。或者我可以找到 java 的现成实现吗?我的项目中有 google maps sdk,但我在那里找不到任何有用的东西。
我猜你的平方半径比地球半径(6371公里)小很多
这样你就可以放心地忽略地球的曲率了。
那么数学就很简单了:
// 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)));
示例:
中心(纬度,经度)在 48.00,11.00
和半径 10
km
将在 48.09,11.13
处给出 NE 角(纬度,经度),在 47.91,10.87
处给出 SW 角(纬度,经度)。
下面是如何使用 LatLng
google-maps-services-java
的 Bounds
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;
}
给定输入、中心纬度、中心经度和以公里为单位的半径,我想获得包含此圆的矩形的坐标(东北和西南 lat/lng)。
我应该自己写方法吗?尽管我害怕不考虑某些事情,因为我的数学生锈了。或者我可以找到 java 的现成实现吗?我的项目中有 google maps sdk,但我在那里找不到任何有用的东西。
我猜你的平方半径比地球半径(6371公里)小很多 这样你就可以放心地忽略地球的曲率了。
那么数学就很简单了:
// 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)));
示例:
中心(纬度,经度)在 48.00,11.00
和半径 10
km
将在 48.09,11.13
处给出 NE 角(纬度,经度),在 47.91,10.87
处给出 SW 角(纬度,经度)。
下面是如何使用 LatLng
google-maps-services-java
的 Bounds
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;
}