本文介绍了distanceTo返回多少距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否考虑到海拔高度的变化?
Does it take into account altitude changes?
我的意思是,如果我从该三角形的左顶点开始并在右上顶点结束,它返回的距离是a还是b?
I mean, if I start in left vertex of this triangle and end in the right upper vertex, does it return distance a or b?
double distanceInMetersFloat = initialPosition.distanceTo(finalPosition);
在我的应用中,initialPosition和finalPosition都是具有高度的位置(我使用Google Elevation API对其进行了设置).
In my app, both initialPosition and finalPosition are Location with altitudes (I set them with Google Elevation API).
根据Google:
但是您可以在有或没有海拔的情况下做到这一点.
But you can do it with or without altitudes.
推荐答案
计算 Location.distanceTo
时不考虑海拔高度.
The altitude is not taken into account when computing Location.distanceTo
.
您可以像这样测试它:
Location location1 = new Location("");
location1.setLatitude(40);
location1.setLongitude(-4);
location1.setAltitude(0);
Location location2 = new Location("");
location2.setLatitude(30);
location2.setLongitude(-3);
location2.setAltitude(0);
Location location3 = new Location("");
location3.setLatitude(30);
location3.setLongitude(-3);
location3.setAltitude(100);
Log.e("Without altitude", ""+location1.distanceTo(location2));
Log.e("With altitude", ""+location1.distanceTo(location3));
Log.e("Different altitude", ""+location2.distanceTo(location3));
这是输出:
E/有海拔:1113141.5
E/不同高度:0.0
这篇关于distanceTo返回多少距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!