我有一个问题, 如何设置取决于当前速度的缩放级别? 例如,当移动缓慢。缩放到近处,快速时,缩放到远处。
这是我的算法:
private int calculateZoomLevelBySpeed(float speed) {
int zoomLevelMax = mapView.getMaxZoomLevel();
// default
int zoomLevel = (zoomLevelMax > 0) ? (int)zoomLevelMax / 2 : 4;
if (speed > 0) {
// 300km theoretically max / max zoom steps
double step = 300 / zoomLevelMax;
zoomLevel = (int) Math.round(speed / step);
// reverse
zoomLevel = zoomLevelMax - zoomLevel;
zoomLevel = Math.min(zoomLevelMax, zoomLevelMax);
zoomLevel = Math.max(zoomLevelMax, 1);
}
return zoomLevel;
}
这不起作用,我该怎么做?
提前致谢。
答案 0 :(得分:-1)
private int calculateZoomLevelBySpeed(float speed)
{
//assuming this line returns the max zoom level on maps
int zoomLevelMax = mapView.getMaxZoomLevel();
// default
int zoomLevel = (zoomLevelMax > 0) ? (int)zoomLevelMax / 2 : 4;
if (speed > 0) {
// 300km theoretically max / max zoom steps
double step = (speed / 300) * zoomLevelMax;
}
return Math.Round(zoomLevel);
}
答案 1 :(得分:-1)
试试这样:
private int calculateZoomLevelBySpeed(float speed) {
int zoomLevelMax = mapView.getMaxZoomLevel();
if (speed > 0) {
// 300km theoretically max / max zoom steps
double step = 300 / zoomLevelMax;
zoomLevel = (int) Math.round(speed / step);
// reverse
zoomLevel = zoomLevelMax - zoomLevel;
}
return zoomLevel;
}