地理圆到矩形坐标

pre*_*oid 2 java google-maps latitude-longitude

给定输入、中心纬度、中心经度和半径(以公里为单位),我想获取包含该圆的矩形的坐标(东北和西南纬度/经度)。

我应该自己编写方法吗?尽管我害怕不考虑某些事情,因为我的数学很生疏。或者我可以找到一个现成的java实现吗?我的项目中有谷歌地图 sdk,但我在那里找不到任何有用的东西。

Tho*_*sch 5

我想你的平方半径比地球的半径(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))); 
Run Code Online (Sandbox Code Playgroud)

例子:

Center(lat,lon) at48.00,11.00和半径10km
将给出 NE-corner(lat,lon) at 48.09,11.13和 SW-corner(lat,lon) at 47.91,10.87

这里是如何与做LatLngBounds的的google-maps-services-javaAPI:

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;
}
Run Code Online (Sandbox Code Playgroud)