Android的查找纬度经度第X点从定义的位置 [英] Android Find Latitude Longitude Of X point From Defined Location

查看:199
本文介绍了Android的查找纬度经度第X点从定义的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时工作安卓 图形页面和发展一个基于地图的应用程序。我需要找到从具体坐标的X距离。方向不是我的首要任务距离为我的首要任务让说我需要找到100米的特定位置上的我怎么能做到这一点的任何想法 先谢谢您的阅读和回答。

i m working on Android MapView and developing a map based Application. i Need to find an X distance from the Specific Co-ordinates. Direction is not my priority Distance is my priority let say i need to find 100 meters from a particular location any idea on how can i do that Thanks in advance for reading and answering.

推荐答案

为了计算上找到一个给定的距离原点,你需要有一个轴承(或方向)线上的点还有距离。这里是一个函数,将采取一个起始位置,轴承和距离(深度),并返回一个目标位置(Android版):你可能希望从KM CONVER到米或任何

in order to calculate to find a point on a line a given distance away from an origin, you need to have a bearing (or direction) as well as the distance. Here is a function that will take a starting location, a bearing and a distance (depth) and return a destination location (for Android): You may want to conver it from KM to Meters or whatever.

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点从定义的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆