在用户交互之前,GoogleMap不会加载详细地图 [英] GoogleMap won't load detailed map until user interaction

查看:100
本文介绍了在用户交互之前,GoogleMap不会加载详细地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在android上编写一个应用程序,该应用程序将显示google maps中的地图.当我启动应用程序时,地图将以当前位置为中心.使用animateCamera时,我可以看到整个世界的放大动画,直到它聚焦在当前位置为止.

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

如果我触摸屏幕,图像将保持良好状态,直到我行驶几百米,然后再次无法使用.有时会出现图像,但每10公里仅显示1到2次.

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.

这是我在LocationListener::onLocationChanged内移动相机的方式:

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

我该怎么解决?

谢谢

推荐答案

找到的解决方案:

animateCamera.从另一个线程(传感器的线程)调用LocationListener.

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

所以代码变成了:

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

这篇关于在用户交互之前,GoogleMap不会加载详细地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆