如何获得直线距离之间的两个位置中的Andr​​oid? [英] How to get straight distance between two location in android?

查看:191
本文介绍了如何获得直线距离之间的两个位置中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先阅读问题仔细...

First read Question carefully ...

我需要的直线距离 不走路,汽车,或等。

看看下面这给这一形象,

Take a look to this image which given below,

谷歌提供给我们距离车和驾驶。

Google provide us distance by car and driving.

但我不想要它,我想直线距离之间的两个位置(纬度 - 经度)

But I don't want it, I want straight distance between two location (latitude - longitude).

将显示为为红线。

注意:我不希望把红线在谷歌地图,只是想在单位的远程(英里,公里等)

NOTE : I don't want to put red line on Google map, just want the Distance in Units(mile,km,etc.)

推荐答案

机器人

double distance

Location locationA = new Location("point A")

locationA.setLatitude(latA);

locationA.setLongitude(lngA);

Location locationB = new Location("point B");

locationB.setLatitude(latB);

LocationB.setLongitude(lngB);

distance = locationA.distanceTo(locationB);

MATHEMATICALY

a = distance in degrees //meterConversion = 1609;

b = 90 - latitude of point 1

c = 90 - latitude of point 2

l = longitude of point 1 - longitude of point 2

Cos(a) = Cos(b)Cos(c) + Sin(b)Sin(c)Sin(l)

d = circumference of Earth * a / 360 // circumference of Earth = 3958.7558657440545D km

这篇关于如何获得直线距离之间的两个位置中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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