Drop marker slowly from top of screen to location on android map V2

后端 未结 4 956
攒了一身酷
攒了一身酷 2021-02-03 16:18

I am using android maps v2works fine I can add and remove markers onLong Touch on locations.

Problem: I would like to drop the marker slowly into the to

4条回答
  •  被撕碎了的回忆
    2021-02-03 16:50

    You can achieve this with a code similar to this (untested):

    final LatLng target = ...;
    
    final long duration = 400;
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    
    Point startPoint = proj.toScreenLocation(target);
    startPoint.y = 0;
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    
    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                // Post again 10ms later.
                handler.postDelayed(this, 10);
            } else {
                // animation ended
            }
        }
    });
    

提交回复
热议问题