From aac539596fe4f9f829679427298217c584216a84 Mon Sep 17 00:00:00 2001 From: davinci9196 Date: Mon, 4 Nov 2024 10:58:05 +0800 Subject: [PATCH] Optimize the phenomenon of Uber route drift --- .../org/microg/gms/maps/hms/GoogleMap.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt index aa5911f805..7f480ac364 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt @@ -87,7 +87,8 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) private var storedMapType: Int = options.mapType val waitingCameraUpdates = mutableListOf() - var locationEnabled: Boolean = false + private var isCameraMoving: Boolean = false + private val updateCameraMoveRun = Runnable { isCameraMoving = false } private var markerId = 0L val markers = mutableMapOf() @@ -306,8 +307,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) internalOnInitializedCallbackList.add(it.getMapReadyCallback()) } - override fun getProjection(): IProjectionDelegate = - map?.projection?.let { ProjectionImpl(it) } ?: DummyProjection() + override fun getProjection(): IProjectionDelegate { + return if (isCameraMoving) DummyProjection() else map?.projection?.let { ProjectionImpl(it) } ?: DummyProjection() + } override fun setOnCameraChangeListener(listener: IOnCameraChangeListener?) = afterInitialize { Log.d(TAG, "setOnCameraChangeListener"); @@ -493,6 +495,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraMoveStartedListener = listener hmap.setOnCameraMoveStartedListener { try { + Log.d(TAG, "setCameraMoveStartedListener: ") + view.removeCallbacks(updateCameraMoveRun) + isCameraMoving = true cameraMoveStartedListener?.onCameraMoveStarted(it) } catch (e: Exception) { Log.w(TAG, e) @@ -505,15 +510,15 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraMoveListener = listener it.setOnCameraMoveListener { try { + Log.d(TAG, "setOnCameraMoveListener: ") + isCameraMoving = true if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - if(mapView != null){ - if(mapView!!.parent != null){ - mapView!!.parent.onDescendantInvalidated(mapView!!,mapView!!) - } - } + view.onDescendantInvalidated(mapView!!, mapView!!) } + view.removeCallbacks(updateCameraMoveRun) cameraMoveListener?.onCameraMove() cameraChangeListener?.onCameraChange(map?.cameraPosition?.toGms()) + view.postDelayed(updateCameraMoveRun, 200) } catch (e: Exception) { Log.w(TAG, e) } @@ -525,6 +530,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraMoveCanceledListener = listener it.setOnCameraMoveCanceledListener { try { + Log.d(TAG, "setOnCameraMoveCanceledListener: ") + view.removeCallbacks(updateCameraMoveRun) + isCameraMoving = false cameraMoveCanceledListener?.onCameraMoveCanceled() } catch (e: Exception) { Log.w(TAG, e) @@ -537,6 +545,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraIdleListener = listener it.setOnCameraIdleListener { try { + Log.d(TAG, "setOnCameraIdleListener: ") + view.removeCallbacks(updateCameraMoveRun) + isCameraMoving = false cameraIdleListener?.onCameraIdle() } catch (e: Exception) { Log.w(TAG, e)