谷歌地图Android api v2折线长度
我正在尝试找到android maps api v2方法,它将决定我在移动时创建的折线的长度。 我会把它放在onLocationChanged()中以进行持续更新。 任何人都知道方法是什么以及地图api将显示长度的单位?
Polyline line = map.addPolyline(new PolylineOptions()); public void onLocationChanged(Location location) { line.add(new LatLng(location.getLatitude(), location.getLongitude()) .width(5) .color(Color.RED)); }
您可以将最后一个位置的Location.distanceBetween用于当前位置。 如果您想要距离起点和终点位置的总距离,请随着位置的变化保持总计
我遇到过同样的问题。 这是我能够解决它的方式。
-
private ArrayList
在位置更改时将位置添加到ArrayList。mLatLngList; - 使用Gradle将此http://googlemaps.github.io/android-maps-utils/库导入您的项目或
compile 'com.google.maps.android:android-maps-utils:0.4'
- 导入库
import com.google.maps.android.SphericalUtil;
-
double distance = SphericalUtil.computeLength(mLatLngList);
我有同样的问题。 这是我的解决方案,其中points是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; }
- 这种依赖性给了我一个jar的两个版本。 我该如何解决?
- gson与混合阅读
- 通过摄像头拍照并以bytearray的forms发送到服务器
- 将linux时间戳转换为android日期
- 在android项目中包含gturri android xml rpc库
- javax.net.ssl.SSLException:读取错误:ssl = 0x56e63588:系统调用期间的I / O错误,同级连接重置
- 在android中实现关键字
- 暂停和恢复AsyncTasks? (机器人)
- 如何处理“org.openqa.selenium.WebDriverException:ChromeDriver只支持BMP中的字符”exception?