@@ -2,7 +2,6 @@ package com.google.samples.quickstart.canonical
2
2
3
3
import android.Manifest
4
4
import android.app.Activity
5
- import android.content.ContentValues.TAG
6
5
import android.content.pm.PackageManager
7
6
import android.location.Location
8
7
import androidx.fragment.app.Fragment
@@ -13,6 +12,7 @@ import android.view.LayoutInflater
13
12
import android.view.View
14
13
import android.view.ViewGroup
15
14
import android.widget.LinearLayout
15
+ import android.widget.Toast
16
16
import androidx.core.content.ContextCompat.checkSelfPermission
17
17
import com.google.android.gms.location.FusedLocationProviderClient
18
18
import com.google.android.gms.location.LocationServices
@@ -78,7 +78,6 @@ class MapsFragment : Fragment() {
78
78
private fun setPlacesSearchBias () {
79
79
// Search nearby result
80
80
currentLatLng?.let {
81
- Log .i(TAG , " currentLatLng" )
82
81
autocompleteFragment.setLocationBias(
83
82
RectangularBounds .newInstance(
84
83
LatLng (currentLatLng!! .latitude - 1 , currentLatLng!! .longitude - 1 ),
@@ -96,7 +95,7 @@ class MapsFragment : Fragment() {
96
95
97
96
// Add and adjust the position of MyLocation button.
98
97
map.isMyLocationEnabled = true
99
- map.setPadding(0 ,(getString (R .string .padding_ratio).toFloat( ) * autocompleteLayout.height).toInt(),0 ,0 )
98
+ map.setPadding(0 , (resources.getFloat (R .dimen .padding_ratio) * autocompleteLayout.height).toInt(),0 ,0 )
100
99
101
100
fusedLocationClient.lastLocation.addOnSuccessListener(this .activity as Activity ) { location ->
102
101
// Got last known location. In some rare situations this can be null.
@@ -105,16 +104,18 @@ class MapsFragment : Fragment() {
105
104
currentLatLng = LatLng (location.latitude, location.longitude)
106
105
map.animateCamera(CameraUpdateFactory .newLatLngZoom(
107
106
currentLatLng,
108
- getString (R .string .zoom_value).toFloat( )
107
+ resources.getFloat (R .dimen .zoom_value)
109
108
))
110
109
map.addMarker(MarkerOptions ()
111
110
.position(currentLatLng!! )
112
111
.title(getString(R .string.my_location_title)))
113
112
map.moveCamera(CameraUpdateFactory .newLatLngZoom(
114
113
currentLatLng,
115
- getString (R .string .zoom_value).toFloat( )
114
+ resources.getFloat (R .dimen .zoom_value)
116
115
))
117
116
setPlacesSearchBias()
117
+ } ? : run {
118
+ Toast .makeText(context, getString(R .string.cannot_access_location), Toast .LENGTH_SHORT )
118
119
}
119
120
}
120
121
}
@@ -129,7 +130,7 @@ class MapsFragment : Fragment() {
129
130
}
130
131
131
132
override fun onError (status : Status ) {
132
- Log .e(TAG , " An error occurred: $status " )
133
+ Log .e(" Mapfragment " , " An error occurred: $status " )
133
134
}
134
135
})
135
136
}
@@ -155,7 +156,7 @@ class MapsFragment : Fragment() {
155
156
targetMarker?.remove()
156
157
map.moveCamera(CameraUpdateFactory .newLatLngZoom(
157
158
targetLatLng,
158
- getString (R .string .zoom_value).toFloat( )
159
+ resources.getFloat (R .dimen .zoom_value)
159
160
))
160
161
targetMarker = map.addMarker(MarkerOptions ()
161
162
.position(targetLatLng)
0 commit comments