GoogleMap won't load detailed map until user i

2020-05-07 06:32发布

I'm writing an application on android that will show a map from google maps. When I start the app, the map is centered on the current location. When I use animateCamera, I can see the zoom-in animation from the whole world until it focuses on current location.

The problem is that I need to touch the map to get the map to display at the zoom level I expected.

Here is what I get before I touch the screen : Before touch

Here is what I get after having touch the screen : After touch

If I touch the screen, the image will remain fine, until I drive a few hundred meters and then it's again unuseable. Sometimes the image appears, but it's only 1 or 2 times per 10km.

Here is how I move the camera inside LocationListener::onLocationChanged :

float zoom = 19.0f;

LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
// moving car marker
m_locationMarkerG.setPosition(target);
m_locationMarkerG.setRotation(location.getBearing());

// tilting camera depending on speed
float tilt = Math.min(90, location.getSpeed()*10);
m_mapViewG.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder().zoom(zoom).bearing(location.getBearing()).
        target(target).tilt(tilt).build()));

What could I try to solve this ?

Thanks

1条回答
Root(大扎)
2楼-- · 2020-05-07 06:53

Found solution :

animateCamera MUST be called from the main looper. The LocationListener is called from another thread (sensor's thread).

So the code become :

final float zoom = 19.0f;

final LatLng target = new LatLng(location.getLatitude(), location.getLongitude());

// tilting camera depending on speed
final float tilt = Math.min(90, location.getSpeed()*10);

m_handler.post(new Runnable() {
    public void run() {
        // moving car marker
        m_locationMarkerG.setPosition(target);
        m_locationMarkerG.setRotation(location.getBearing());

        // moving camera
        m_mapViewG.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder().zoom(zoom).bearing(location.getBearing()).target(target).tilt(tilt).build()));
    }
});
查看更多
登录 后发表回答