我正在尝试在谷歌地图上绘制路径。我已经能够在起点和终点之间绘制路径,但我想要在移动时绘制路径。请帮助我在谷歌地图上实现这一点。
谢谢, 莫娜丽
我正在尝试在谷歌地图上绘制路径。我已经能够在起点和终点之间绘制路径,但我想要在移动时绘制路径。请帮助我在谷歌地图上实现这一点。
谢谢, 莫娜丽
在方法onLocationChanged中注册LocationListener,并绘制起点和目标点之间的路径。
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
}
...
}
收集数组中最新的N个点。每次更新数组时,重新绘制所有值。使用覆盖层在其上绘制线条。