Android v2 maps get low when the map area automatically moves

I simulate a car moving along a prerecorded path on v2 Android cards. When I extend the route manually, it works fine, but when I move the camera along the path using mMap.animateCamera() , it does not load the visible area of ​​the map, I get a very uneven, poor quality map. If I touch the screen and move the map a little or zoom in a little, then it will load this part again.

How can I achieve that it always clearly displays the visible part?

EDIT: I added an example image: this is what I see when I do not touch the map. After I touch it, it becomes clear (similar to the bottom left).

Example image

EDIT2: I have an idea that this is because Google wants to prevent map caching by quickly moving the camera across an area. Is it possible that this is the cause of this problem? (The map shows Budapest, Hungary, part of which you cannot download for offline use ...) But here I want to show only animation and place markers, I only need a visible area that needs to be cached - is there any way around this behavior?

EDIT3: Animation Code:

 new Thread(new Runnable() { @Override public void run() { // ... Calculating and sending new location, in an infinite loop with sleeps for timing MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); } }); } }).start(); 
+6
source share
2 answers

Finally found a solution. I was able to recreate your problem using the code you provided. I replaced your code with the following and it worked for me.

  Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // ... Calculating and sending new location, in an infinite loop with sleeps for timing MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); } }); } }, 0, 2000); 

Just delete your sleep code and replace the last argument in scheduleAtFixedRate (2000) with whatever value you used for sleep.

+2
source

I had the same problem. Since this did not happen when the camera was not animated, this should have been connected with this.

In this case, the camera must be able to complete its work before it updates the background / roads, etc. Since my application updates the position every second, and the map takes about 2 seconds to complete, I get rough roads and the environment in general.

The solution is to use one of the animateCamera overloads:

 public final void animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback) 

Moving the map in accordance with the update by animation over the specified duration, and causes an additional callback at the end. See CameraUpdateFactory for a set of updates.

I used a duration of 900 ms for my case, so the animation runs before it gets a new location.

To make the callback work, you need to implement GoogleMap.CancelableCallback for your class. To do this, add two overrides:

 @Override public void onFinish() { } @Override public void onCancel() { } 

They are not required to solve the problem, although you can add additional logic there.

A camera update call might look like this:

 cameraPosition = new CameraPosition.Builder() .target(current) .zoom(zoomLevel) .bearing(bearing) .tilt(tilt) .build(); CameraUpdate update = CameraUpdateFactory.newCameraPosition(cameraPosition); map.animateCamera(update, 900, this); 
+1
source

Source: https://habr.com/ru/post/969377/


All Articles