Google map: moving marker and map together smoothly along with the user?

后端 未结 1 1752
栀梦
栀梦 2021-01-21 09:31

I have to show real time/live user moving location in google map once user turn on the feature and up-to terminating it.

I have had used the method below to animate the

1条回答
  •  [愿得一人]
    2021-01-21 09:55

    • What I done in my similar project is like: Assume I have a list of point where user navigated one by one so, I want to display that trip in map with animation. Instead of moving both marker and camera same time you can move marker between two points and then animate camera to that second point, now again move marker to next point and then when marker reach out next point animate your camera.

    To get this working you have to modify your code little bit. Add this code:

        private static final int ANIMATE_SPEEED_TURN = 1000;
        private static final int BEARING_OFFSET = 20;    
    
        if (t < 1) {
                mHandler.postDelayed(this, 16);
            } else {
    
             // your code
             if (hideMarker) {
                        marker.setVisible(false);
                    } else {
                        marker.setVisible(true);
                    }
    
    
             //my added code
                    LatLng begin = getBeginLatLng();// current point
                    LatLng end = getEndLatLng();// next point
    
                    float bearingL = bearingBetweenLatLngs(begin, end);  
    
                    CameraPosition cameraPosition =
                            new CameraPosition.Builder()
                                    .target(end)
                                    .bearing(bearingL + BEARING_OFFSET)
                                    .tilt(tilt)
                                    .zoom(googleMap.getCameraPosition().zoom)
                                    .build();
    
                    googleMap.animateCamera(
                            CameraUpdateFactory.newCameraPosition(cameraPosition),
                            ANIMATE_SPEEED_TURN,
                            null
                    );
    
                    mHandler.postDelayed(animator, 16);
    
                }
    

    Let me know If anything goes wrong!!! For detailed step visit Animating the map

    0 讨论(0)
提交回复
热议问题