简体   繁体   English

从某个地理距离获取位置

[英]Get location from a distance of a geographic point

I am working on an Android app and I have latitude and longitude of a geographic point and I would like to get coordinates of the place located from X meters (North) and Y meters (West). 我正在使用Android应用程序,并且具有某个地理点的经度和纬度,因此我希望从X米(北)和Y米(西)获得该地点的坐标。 GeoPoint does not implement this kind of functionality so I have to find a way to do it by myself... GeoPoint不会实现这种功能,因此我必须自己找到一种方法来实现。

I made some searches but I did not find anything interesting, do you have any idea how to proceed? 我进行了一些搜索,但没有发现任何有趣的东西,您知道如何进行吗?

Tricky, because the distance between two whole longitudes depends on the latitude, and the distance also depends on the altitude... 棘手的,因为两个完整经度之间的距离取决于纬度,并且距离也取决于海拔高度...

To make things simple, I'd try and guess the longitude and latitude, and check the distance between the guess and the origin point. 为简单起见,我将尝试猜测经度和纬度,并检查猜测与起点之间的距离。 This is easier because getting the distance between two points has already been done. 这很容易,因为已经完成了获取两点之间的距离的操作。

Start with one axis, and do a kind of binary search until you find the location X meters to the north. 从一个轴开始,并进行某种二值搜索,直到找到北距X米的位置。 Then do the same for the other axis. 然后对另一个轴执行相同的操作。

With the following method you will get the latitude and longitude to add to the original location to get to the final one. 使用以下方法,您将获得要添加到原始位置的纬度和经度,然后到达最后一个纬度。 Have in mind that this only works over relatively small distances, as it is ignoring the earth curvature. 请记住,由于它忽略了地球曲率,因此仅在相对较小的距离上有效。

private static final float GAP_LAT_LON = 0.00005f; //aprox 5 meters
private float results[] = new float[1];

private PointF getGaps(Location initial, float distanceX, float distanceY, PointF gaps){
    Location.distanceBetween(initial.getLatitude(), initial.getLongitude(), initial.getLatitude(), initial.getLongitude() + GAP_LAT_LON, results);
    double factorX = GAP_LAT_LON / results[0];
    Location.distanceBetween(initial.getLatitude(), initial.getLongitude(), initial.getLatitude() + GAP_LAT_LON, initial.getLongitude(), results);
    double factorY = GAP_LAT_LON / results[0];
    if(gaps == null)
        gaps = new PointF();
    gaps.set((float)(distanceX * factorX), (float)(distanceY * factorY));
    return gaps;
}

//to use
private void teste(){
    PointF gaps = null;
    Location initial = new Location("");

    initial.setLatitude(23.5);
    initial.setLongitude(13.2);

    //100 meters West/East and 300 meters North/South
    getGaps(initial, 100, 300, gaps);

    //gaps.x returns x offset to add/subtract to initial latitude
    //gaps.y returns y offset to add/subtract to initial longitude
}

good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM