@@ -49,7 +49,7 @@ class MapsFragment : Fragment() {
49
49
private const val LOCATION_PERMISSION_REQUEST_CODE = 1
50
50
private const val ZOOM_VALUE = 14f
51
51
private const val PADDING_RATIO = 1.5
52
- private const val MAP_FRAGMENT_TAG = " Mapfragment"
52
+ private const val FRAGMENT_TAG = " Mapfragment"
53
53
}
54
54
55
55
override fun onRequestPermissionsResult (requestCode : Int ,
@@ -99,33 +99,29 @@ class MapsFragment : Fragment() {
99
99
map.isMyLocationEnabled = true
100
100
map.setPadding(0 , (PADDING_RATIO * autocompleteLayout.height).toInt(),0 ,0 )
101
101
102
- fusedLocationClient.lastLocation
103
- .addOnSuccessListener { location ->
102
+ fusedLocationClient.lastLocation.addOnSuccessListener { location ->
104
103
// Got last known location. In some rare situations this can be null.
105
- location?.let {
106
- Log .d(MAP_FRAGMENT_TAG , " Locating Success ${location.latitude} , ${location.longitude} " )
107
- lastLocation = location
108
- currentLatLng = LatLng (location.latitude, location.longitude)
109
- map.animateCamera(CameraUpdateFactory .newLatLngZoom(
110
- currentLatLng,
111
- ZOOM_VALUE
112
- ))
113
- map.addMarker(MarkerOptions ()
114
- .position(currentLatLng!! )
115
- .title(getString(R .string.my_location_title)))
116
- map.moveCamera(CameraUpdateFactory .newLatLngZoom(
117
- currentLatLng,
118
- ZOOM_VALUE
119
- ))
120
- setPlacesSearchBias()
121
- } ? : run {
122
- Log .d(MAP_FRAGMENT_TAG , " Locating Failed" )
123
- Toast .makeText(context, getString(R .string.cannot_access_location), Toast .LENGTH_SHORT )
124
- }
125
- }
126
- .addOnFailureListener {
127
- Log .d(MAP_FRAGMENT_TAG , " fusedLocationClient.lastLocation Failed" )
104
+ location?.let {
105
+ Log .d(FRAGMENT_TAG , " Locating Success ${location.latitude} , ${location.longitude} " )
106
+ lastLocation = location
107
+ currentLatLng = LatLng (location.latitude, location.longitude)
108
+ map.animateCamera(CameraUpdateFactory .newLatLngZoom(
109
+ currentLatLng,
110
+ ZOOM_VALUE
111
+ ))
112
+ map.addMarker(MarkerOptions ()
113
+ .position(currentLatLng!! )
114
+ .title(getString(R .string.my_location_title)))
115
+ map.moveCamera(CameraUpdateFactory .newLatLngZoom(
116
+ currentLatLng,
117
+ ZOOM_VALUE
118
+ ))
119
+ setPlacesSearchBias()
120
+ } ? : run {
121
+ Log .d(FRAGMENT_TAG , " Locating Failed" )
122
+ Toast .makeText(context, getString(R .string.cannot_access_location), Toast .LENGTH_SHORT )
128
123
}
124
+ }
129
125
}
130
126
131
127
private fun setUpAutocomplete (autocompleteFragment : AutocompleteSupportFragment , mapFragment : SupportMapFragment ) {
@@ -138,7 +134,7 @@ class MapsFragment : Fragment() {
138
134
}
139
135
140
136
override fun onError (status : Status ) {
141
- Log .e(MAP_FRAGMENT_TAG , " An error occurred: $status " )
137
+ Log .e(FRAGMENT_TAG , " An error occurred: $status " )
142
138
}
143
139
})
144
140
}
0 commit comments