Skip to content

Commit 44c8512

Browse files
authored
refactor: Streamline location handling in AutocompleteAddressActivity (#998)
Removes the unnecessary nullable member variable `deviceLocation` and replaces it with a local, non-nullable variable within the `getAndCompareLocations` method. This change improves null safety and adheres to more idiomatic Kotlin scoping practices, making the code cleaner and more robust without altering functionality. Update dependencies for Kotlin demo
1 parent 97da8ea commit 44c8512

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class AutocompleteAddressActivity : BaseActivity(),
6060
private var marker: Marker? = null
6161
private var checkProximity = false
6262
private lateinit var binding: AutocompleteAddressActivityBinding
63-
private var deviceLocation: LatLng? = null
6463
private val acceptedProximity = 150.0
6564
private var startAutocompleteIntentListener = View.OnClickListener { view: View ->
6665
view.setOnClickListener(null)
@@ -177,16 +176,16 @@ class AutocompleteAddressActivity : BaseActivity(),
177176
if (location == null) {
178177
return@addOnSuccessListener
179178
}
180-
deviceLocation = LatLng(location.latitude, location.longitude)
179+
val currentLocation = LatLng(location.latitude, location.longitude)
181180
// [START_EXCLUDE]
182-
Log.d(TAG, "device location = $deviceLocation")
181+
Log.d(TAG, "device location = $currentLocation")
183182
Log.d(TAG, "entered location = $enteredLocation")
184183

185184
// [START maps_solutions_android_location_distance]
186185
// Use the computeDistanceBetween function in the Maps SDK for Android Utility Library
187186
// to use spherical geometry to compute the distance between two Lat/Lng points.
188187
val distanceInMeters: Double =
189-
computeDistanceBetween(deviceLocation, enteredLocation)
188+
computeDistanceBetween(currentLocation, enteredLocation)
190189
if (distanceInMeters <= acceptedProximity) {
191190
Log.d(TAG, "location matched")
192191
// TODO: Display UI based on the locations matching

demo-kotlin/gradle/libs.versions.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[versions]
2-
androidGradlePlugin = "8.13.0"
2+
androidGradlePlugin = "8.13.2"
33
appcompat = "1.7.1"
44
coreKtx = "1.17.0"
55
glide = "5.0.5"
6-
kotlin = "2.2.20"
6+
kotlin = "2.2.21"
77
mapsSecretsGradlePlugin = "2.0.1"
8-
mapsUtilsKtx = "5.2.0"
8+
mapsUtilsKtx = "5.2.1"
99
material = "1.13.0"
1010
multidex = "2.0.1"
11-
places = "5.0.0"
12-
viewbinding = "8.13.0"
11+
places = "5.1.1"
12+
viewbinding = "8.13.2"
1313
volley = "1.2.1"
14-
kotlinParcelize = "2.2.20"
14+
kotlinParcelize = "2.3.0"
1515

1616
[libraries]
1717
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }

0 commit comments

Comments
 (0)