here-android-sdk-examples
here-android-sdk-examples copied to clipboard
How to zoom in and out the map maintaining the course to destination?
Here is the current implementation of zoom in and out of the map during navigation.
ivZoomIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NavigationManager.getInstance().setMapUpdateMode(NavigationManager.MapUpdateMode.NONE);
m_map.setZoomLevel(m_map.getZoomLevel() + 0.5, Map.Animation.BOW);
tvReCenter.setVisibility(View.VISIBLE);
}
});
ivZoomOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NavigationManager.getInstance().setMapUpdateMode(NavigationManager.MapUpdateMode.NONE);
m_map.setZoomLevel(m_map.getZoomLevel() - 0.5, Map.Animation.BOW);
tvReCenter.setVisibility(View.VISIBLE);
tvReCenter.setVisibility(View.VISIBLE);
}
});
tvReCenter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
m_navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
GeoPosition lkp = PositioningManager.getInstance().getLastKnownPosition();
if (lkp != null && lkp.isValid())
m_map.setCenter(lkp.getCoordinate(), Map.Animation.BOW);
tvReCenter.setVisibility(View.GONE);
m_map.setZoomLevel(17.0f, Map.Animation.BOW);
}
});
With current implementation when we zoom in or out the map, the map remains still at the current position where it was zoomed and the position indication icon goes out of the map course to the destination. Actually we want to zoom in/out the map maintaining map updates and position indicator update. The reason of not updating the map is due to NavigationManager.getInstance().setMapUpdateMode(NavigationManager.MapUpdateMode.NONE);
but the problem is if we don't this, the zoom in/out out the map doesn't work.
If we zoom the map with the below code it didn't zoom.
ivZoomOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
m_map.setZoomLevel(m_map.getZoomLevel() - 0.5, Map.Animation.BOW);
}
});
@starand can you please help?
Hi @binod-techindustan
Did you try using RoadView
class to zoom in or out during navigation?
E.g. instead of this:
m_map.setZoomLevel(m_map.getZoomLevel() - 0.5, Map.Animation.BOW);
call this:
NavigationManager.getInstance().getRoadView().zoomOut();
@binod-techindustan did you try this approach?
@NazarKacharaba tried it but didn't worked as expected.
Could you tell what exactly did not work for you? There is another more hacky way to achieve what you need, try this snippet:
final Handler handler = new Handler(Looper.getMainLooper());
void zoomInOut(boolean zoomIn) {
handler.removeCallbacksAndMessages(null);
final NavigationManager navigationManager = NavigationManager.getInstance();
// stop any map movements to set zoom level
navigationManager.setMapUpdateMode(MapUpdateMode.NONE);
map.setZoomLevel(map.getZoomLevel() + (zoomIn ? 0.5 : -0.5), Map.Animation.LINEAR);
// wait until zoom is set
handler.postDelayed(new Runnable() {
@Override
public void run() {
navigationManager.setMapUpdateMode(MapUpdateMode.POSITION_ANIMATION);
}
}, 2000/*time to wait until LINEAR zoom animation is done*/);
}
@NazarKacharaba with NavigationManager.getInstance().getRoadView().zoomOut();
it didn't do anything in the map. I will try the new one.
Thanks @NazarKacharaba the last one works fine
@NazarKacharaba after zoom in/out with this the position indicator icon began to flicker. It's like jumping the position indicator. But after recenter it begin to work smoothly. Here is recenter code:
tvReCenter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
m_navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
GeoPosition lkp = PositioningManager.getInstance().getLastKnownPosition();
if (lkp != null && lkp.isValid())
m_map.setCenter(lkp.getCoordinate(), Map.Animation.BOW);
tvReCenter.setVisibility(View.GONE);
m_map.setZoomLevel(17.0f, Map.Animation.BOW);
});
So can we zoom the map level with map update mode NavigationManager.MapUpdateMode.ROADVIEW
?
@binod-techindustan In NavigationManager.MapUpdateMode.ROADVIEW
mode you should use NavigationManager.getInstance().getRoadView().zoomOut()
or NavigationManager.getInstance().getRoadView().zoomIn()
methods.