@@ -34,7 +34,7 @@ import com.google.android.gms.maps.model.*
3434import kotlinx.coroutines.*
3535
3636class Maps (context : Context , attributeSet : AttributeSet ) : CustomMaps(context, attributeSet),
37- SensorEventListener {
37+ SensorEventListener {
3838
3939 private val accelerometerReadings = FloatArray (3 )
4040 private val magnetometerReadings = FloatArray (3 )
@@ -80,10 +80,10 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
8080 isNorthOnly = GPSPreferences .isNorthOnly()
8181
8282 polylineOptions = PolylineOptions ()
83- .width(10f )
84- .jointType(JointType .ROUND )
85- .color(context.resolveAttrColor(R .attr.colorAppAccent))
86- .geodesic(false )
83+ .width(10f )
84+ .jointType(JointType .ROUND )
85+ .color(context.resolveAttrColor(R .attr.colorAppAccent))
86+ .geodesic(false )
8787
8888 if (isCustomCoordinate) {
8989 customLatitude = MainPreferences .getCoordinates()[0 ].toDouble()
@@ -182,6 +182,10 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
182182 if (location.isNotNull()) {
183183 moveMapCamera(LatLng (location!! .latitude, location!! .longitude), zoom)
184184 addMarker(LatLng (location!! .latitude, location!! .longitude))
185+ } else {
186+ kotlin.runCatching {
187+ moveMapCamera(googleMap?.cameraPosition?.target!! , zoom)
188+ }
185189 }
186190 }
187191
@@ -340,7 +344,8 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
340344 }.onFailure {
341345 circle = googleMap?.addCircle(CircleOptions ()
342346 .center(latLng)
343- .radius(if (location!! .speed > 0F ) location!! .speed.toDouble() else location?.accuracy?.toDouble() ? : 0.0 )
347+ .radius(if (location!! .speed > 0F ) location!! .speed.toDouble() else location?.accuracy?.toDouble()
348+ ? : 0.0 )
344349 .clickable(false )
345350 .fillColor(if (location!! .speed > 0F ) ContextCompat .getColor(context, R .color.bearing_circle_color) else LocationPins .getCircleFillColor())
346351 .strokeColor(if (location!! .speed > 0F ) ContextCompat .getColor(context, R .color.bearing_circle_stroke) else LocationPins .getCircleStrokeColor())
@@ -398,7 +403,7 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
398403 }
399404
400405 polylineOptions?.add(LatLng (GPSPreferences .getTargetMarkerCoordinates()[0 ].toDouble(),
401- GPSPreferences .getTargetMarkerCoordinates()[1 ].toDouble()))
406+ GPSPreferences .getTargetMarkerCoordinates()[1 ].toDouble()))
402407
403408 targetPolyline = googleMap?.addPolyline(polylineOptions!! )
404409
@@ -452,23 +457,23 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
452457 isAnimating = true
453458 googleMap?.animateCamera(CameraUpdateFactory .newCameraPosition(
454459 CameraPosition .builder()
455- .target(latLng)
456- .tilt(GPSPreferences .getMapTilt())
457- .zoom(zoom)
458- .bearing(bearing ? : 0F )
459- .build()),
460- cameraSpeed,
461- object : GoogleMap .CancelableCallback {
462- override fun onFinish () {
463- viewHandler.postDelayed(sensorRegistrationRunnable, 100L )
464- isAnimating = false
465- }
466-
467- override fun onCancel () {
468- viewHandler.postDelayed(sensorRegistrationRunnable, 100L )
469- isAnimating = false
470- }
471- })
460+ .target(latLng)
461+ .tilt(GPSPreferences .getMapTilt())
462+ .zoom(zoom)
463+ .bearing(bearing ? : 0F )
464+ .build()),
465+ cameraSpeed,
466+ object : GoogleMap .CancelableCallback {
467+ override fun onFinish () {
468+ viewHandler.postDelayed(sensorRegistrationRunnable, 100L )
469+ isAnimating = false
470+ }
471+
472+ override fun onCancel () {
473+ viewHandler.postDelayed(sensorRegistrationRunnable, 100L )
474+ isAnimating = false
475+ }
476+ })
472477 }
473478
474479 fun setFirstLocation (location : Location ? ) {
@@ -504,7 +509,7 @@ class Maps(context: Context, attributeSet: AttributeSet) : CustomMaps(context, a
504509 }
505510
506511 rotationAngle =
507- CompassAzimuth .calculate(gravity = accelerometer, magneticField = magnetometer)
512+ CompassAzimuth .calculate(gravity = accelerometer, magneticField = magnetometer)
508513
509514 if (isCompassRotation) {
510515 if (googleMap.isNotNull())
0 commit comments