question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to zoom in and out the map maintaining the course to destination?

See original GitHub issue

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);

            }
        });

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
NazarKacharabacommented, Mar 24, 2020

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*/);
}
0reactions
NazarKacharabacommented, Apr 1, 2020

@binod-techindustan In NavigationManager.MapUpdateMode.ROADVIEW mode you should use NavigationManager.getInstance().getRoadView().zoomOut() or NavigationManager.getInstance().getRoadView().zoomIn() methods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quickly Zoom In & Out of Maps with a Tap | OSXDaily
Zoom out by using a two-finger single tap on the active Maps screen · Zoom in by using a one finger double tap...
Read more >
Map panning and zooming methods - Andy Woodruff
Here you click on the map and draw a box, specifying the extent and location to which you wish to zoom. Pros: Efficient...
Read more >
Change the map view in CarPlay - Apple Support
In CarPlay, find your location on a map, zoom in and out, and move the map to see the detail you need.
Read more >
Tutorials/Mapping - Minecraft Wiki - Fandom
To keep zoom-level 1 maps from overlapping, ensure that each is built from a zoom-level zero with x- and z-coordinates that are multiples...
Read more >
Garmin Instinct Watch - Panning and Zooming the Map in ...
garminThis is a quick video to show you how pan and zoom the map during navigation on your Garmin Instinct watch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found