Android从定义的位置查找X点的纬度经度

标签 android google-maps location distance

我正在使用 Android MapView 并开发基于 map 的应用程序。我需要找到与特定 坐标 的 X 距离。方向不是我的首要任务距离是我的首要任务让我说我需要找到距离特定位置 100 米的任何想法我该怎么做 提前感谢您的阅读和回答。

最佳答案

为了通过计算找到距原点给定距离的直线上的点,您需要有方位(或方向)以及距离。这是一个函数,它将获取起始位置、方位角和距离(深度)并返回目的地位置(适用于 Android):您可能希望将其从 KM 转换为米或其他任何格式。

public static Location GetDestinationPoint(Location startLoc, float bearing, float depth) 
{ 
    Location newLocation = new Location("newLocation");

    double radius = 6371.0; // earth's mean radius in km 
    double lat1 = Math.toRadians(startLoc.getLatitude()); 
    double lng1 = Math.toRadians(startLoc.getLongitude()); 
    double brng = Math.toRadians(bearing); 
    double lat2 = Math.asin( Math.sin(lat1)*Math.cos(depth/radius) + Math.cos(lat1)*Math.sin(depth/radius)*Math.cos(brng) ); 
    double lng2 = lng1 + Math.atan2(Math.sin(brng)*Math.sin(depth/radius)*Math.cos(lat1), Math.cos(depth/radius)-Math.sin(lat1)*Math.sin(lat2)); 
    lng2 = (lng2+Math.PI)%(2*Math.PI) - Math.PI;  

    // normalize to -180...+180 
    if (lat2 == 0 || lng2 == 0) 
    {
        newLocation.setLatitude(0.0);
        newLocation.setLongitude(0.0);
    }
    else
    {
        newLocation.setLatitude(Math.toDegrees(lat2));
        newLocation.setLongitude(Math.toDegrees(lng2));
    }

    return newLocation;
};

关于Android从定义的位置查找X点的纬度经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14332348/

相关文章:

android - 新 Activity 的 TabWidget 问题

android - 如何在 Android 上将语音转换为电话?

google-maps - 让相机随着位置的变化而移动(Google map Api)

android - 将谷歌地图链接到 TextView 中的邮政编码

flutter - 是否可以通过 flutter app 共享您的位置

python - 使用正则表达式重新排序字符串

api - 没有 HTML5 API 的地理定位

android - Android 中的 SmsManager SendDataMessage

android - Android 上的 Python 3 使用 TerminalIDE

regex - 谷歌地图的地址格式