Usm*_*urd 4 android location google-maps distance
我正在开发Android MapView和开发基于地图的应用程序.我需要找到特定的X距离Co-ordinates.方向不是我的优先考虑距离是我的优先考虑我需要找到距离特定位置100米的任何想法,我该怎么做才能提前感谢阅读和回答.
为了计算在离原点一定距离的线上找到一个点,你需要有一个方位(或方向)以及距离.这是一个函数,它将获取起始位置,方位和距离(深度)并返回目标位置(对于Android):您可能希望将其从KM转换为Meters或其他任何内容.
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;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |