我正在尝试在谷歌地图中绘制路径。我能够在起点和终点之间绘制一条路径,但我想在移动时绘制路径。当我在google地图上移动时,请帮我绘制路径。
由于 Monali
答案 0 :(得分:4)
注册LocationListener并在方法onLocationChanged中绘制起点和已到达点之间的路径。
private void addLocationListener(LocationListener locationListener) {
LocationProvider locationProvider = getLocationManager().getProvider(LocationManager.GPS_PROVIDER);
getLocationManager().requestLocationUpdates(locationProvider.getName(), LOCATION_UPDATE_INTERVAL,
LOCATION_UPDATE_MIN_DISTANCE, locationListener);
}
private LocationManager getLocationManager() {
return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}
private void startGpsListening(Location start) {
this.startLocation = start;
addLocationListener(new MyLocationListener());
}
private Location startLocation = new Location("");
private class MyLocationListener extends LocationListener {
public void onLocationChanged(Location location) {
Log.d(LOG_TAG, "New location has come: " + location);
// draw path between startLocarion and this location
}
...
}
答案 1 :(得分:0)
收集阵列中的最新N点。每次更新数组时,都会重绘所有值。使用叠加在其上绘制线条。