GoogleMap won't load detailed map until user interaction

后端 未结 1 792
醉话见心
醉话见心 2021-01-28 05:37

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

相关标签:
1条回答
  • 2021-01-28 06:29

    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()));
        }
    });
    
    0 讨论(0)
提交回复
热议问题