缩小时Google Map对象移动

时间:2018-10-10 15:24:58

标签: android google-maps kotlin

当我缩小地图时,具有我当前位置的对象会移动,这是动画代码,请帮助我。

如果您需要更多我的应用程序,请告诉我。

package com.spartons.driverapp.helper

import android.os.Handler
import android.os.SystemClock
import android.view.animation.AccelerateDecelerateInterpolator
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import com.spartons.driverapp.interfaces.LatLngInterpolator

class MarkerAnimationHelper {

fun animateMarkerToGB(marker: Marker, finalPosition:                                              LatLng,latLngInterpolator: LatLngInterpolator) {
    val startPosition = marker.position
    val handler = Handler()
    val start = SystemClock.uptimeMillis()
    val interpolator = AccelerateDecelerateInterpolator()
    val durationInMs = 2000f
    handler.post(object : Runnable {
        var elapsed: Long = 0
        var t: Float = 0.toFloat()
        var v: Float = 0.toFloat()
        override fun run() {
            // Calculate progress using interpolator
            elapsed = SystemClock.uptimeMillis() - start
            t = elapsed / durationInMs
            v = interpolator.getInterpolation(t)
            marker.position = latLngInterpolator.interpolate(v,startPosition,                                     finalPosition)
            // Repeat till progress is complete.
            if (t < 1) {
                // Post again 16ms later.
                handler.postDelayed(this, 16)
                }
            }
        })
    }
}

0 个答案:

没有答案