从屏幕上方慢慢降标记位置上的Andr​​oid地图V2标记、屏幕、位置、地图

2023-09-06 00:58:25 作者:毁我爱她

我使用Android地图v2works罚款,我可以添加和删除标记onLong触摸的位置。

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 touched location i.e. I want the user to see the marker floating from the top of the screen to the point where it is dropped(touched location).

目前,标记只出现在触摸位置,这样你必须抬起你的手指一看就知道它已被删除。这将是很好看到它从屏幕顶部的到来。

Currently; the marker just appears on the touched location such that you have to lift you finger to see that it has been dropped. It would be nice to see it coming from the top of the screen.

感谢。

推荐答案

您可以用code与此类似做到这一点(未经测试):

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