Java 谷歌地图Android api v2多段线长度
我试图找到android maps api v2方法,该方法将确定移动时创建的多段线的长度。我会把它放在onLocationChanged()中,以便不断更新。有人知道该方法是什么,以及maps api将显示长度的单位是什么吗Java 谷歌地图Android api v2多段线长度,java,android,google-maps,polyline,Java,Android,Google Maps,Polyline,我试图找到android maps api v2方法,该方法将确定移动时创建的多段线的长度。我会把它放在onLocationChanged()中,以便不断更新。有人知道该方法是什么,以及maps api将显示长度的单位是什么吗 Polyline line = map.addPolyline(new PolylineOptions()); public void onLocationChanged(Location location) { line.add(new LatLng(loca
Polyline line = map.addPolyline(new PolylineOptions());
public void onLocationChanged(Location location) {
line.add(new LatLng(location.getLatitude(), location.getLongitude())
.width(5)
.color(Color.RED));
}
您可以使用上一个位置到当前位置。如果你想知道你的起点和终点位置之间的总距离,那么在你的位置改变时保持一个跑步总距离我有同样的问题。这是我的解决方案,其中点是PolylineOptions对象
protected float calculateMiles() {
float totalDistance = 0;
for(int i = 1; i < points.getPoints().size(); i++) {
Location currLocation = new Location("this");
currLocation.setLatitude(points.getPoints().get(i).latitude);
currLocation.setLongitude(points.getPoints().get(i).longitude);
Location lastLocation = new Location("this");
currLocation.setLatitude(points.getPoints().get(i-1).latitude);
currLocation.setLongitude(points.getPoints().get(i-1).longitude);
totalDistance += lastLocation.distanceTo(currLocation);
}
return totalDistance;
}
受保护的浮点计算器(){
浮动总距离=0;
对于(int i=1;i
我也有同样的问题。下面是我如何解决这个问题的
private ArrayList mLatLngList代码>
在位置更改时将位置添加到ArrayList
编译'com.google.maps.android:android-maps-utils:0.4'
Import com.google.maps.android.SphericalUtil代码>
double distance=SphericalUtil.computeLength(MLAtlingList)代码>
你想在设备移动时绘制路径吗?@mohammedmomn我只需要移动时创建的多段线的长度。是的,我想让它画出路径,但更重要的是我需要路径长度。谢谢你也许能帮你这是我不想做的。想象一下,我的车在一段时间内处于无网络区域。整个计算都会出错。难道没有一个直接的api可以获取一系列点,然后给出一个距离吗?如果你有没有互联网连接,为什么这很重要?
distance-between
不进行网络调用,并且在哪里定义。distance-to
在位置对象中定义,你需要将它与地球半径相乘。检查计算长度方法这应该被列为有效答案