Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit 94000b1

Browse files
modify value type
1 parent d1453a6 commit 94000b1

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

android/canonical/app/src/main/java/com/google/samples/quickstart/canonical/MapsFragment.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.google.samples.quickstart.canonical
22

33
import android.Manifest
44
import android.app.Activity
5-
import android.content.ContentValues.TAG
65
import android.content.pm.PackageManager
76
import android.location.Location
87
import androidx.fragment.app.Fragment
@@ -13,6 +12,7 @@ import android.view.LayoutInflater
1312
import android.view.View
1413
import android.view.ViewGroup
1514
import android.widget.LinearLayout
15+
import android.widget.Toast
1616
import androidx.core.content.ContextCompat.checkSelfPermission
1717
import com.google.android.gms.location.FusedLocationProviderClient
1818
import com.google.android.gms.location.LocationServices
@@ -78,7 +78,6 @@ class MapsFragment : Fragment() {
7878
private fun setPlacesSearchBias() {
7979
// Search nearby result
8080
currentLatLng?.let {
81-
Log.i(TAG, "currentLatLng")
8281
autocompleteFragment.setLocationBias(
8382
RectangularBounds.newInstance(
8483
LatLng(currentLatLng!!.latitude - 1, currentLatLng!!.longitude - 1),
@@ -96,7 +95,7 @@ class MapsFragment : Fragment() {
9695

9796
// Add and adjust the position of MyLocation button.
9897
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)
10099

101100
fusedLocationClient.lastLocation.addOnSuccessListener(this.activity as Activity) { location ->
102101
// Got last known location. In some rare situations this can be null.
@@ -105,16 +104,18 @@ class MapsFragment : Fragment() {
105104
currentLatLng = LatLng(location.latitude, location.longitude)
106105
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
107106
currentLatLng,
108-
getString(R.string.zoom_value).toFloat()
107+
resources.getFloat(R.dimen.zoom_value)
109108
))
110109
map.addMarker(MarkerOptions()
111110
.position(currentLatLng!!)
112111
.title(getString(R.string.my_location_title)))
113112
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
114113
currentLatLng,
115-
getString(R.string.zoom_value).toFloat()
114+
resources.getFloat(R.dimen.zoom_value)
116115
))
117116
setPlacesSearchBias()
117+
} ?: run{
118+
Toast.makeText(context, getString(R.string.cannot_access_location), Toast.LENGTH_SHORT)
118119
}
119120
}
120121
}
@@ -129,7 +130,7 @@ class MapsFragment : Fragment() {
129130
}
130131

131132
override fun onError(status: Status) {
132-
Log.e(TAG, "An error occurred: $status")
133+
Log.e("Mapfragment", "An error occurred: $status")
133134
}
134135
})
135136
}
@@ -155,7 +156,7 @@ class MapsFragment : Fragment() {
155156
targetMarker?.remove()
156157
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
157158
targetLatLng,
158-
getString(R.string.zoom_value).toFloat()
159+
resources.getFloat(R.dimen.zoom_value)
159160
))
160161
targetMarker = map.addMarker(MarkerOptions()
161162
.position(targetLatLng)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="zoom_value">14f</string>
4-
<string name="padding_ratio">1.5</string>
3+
<item name="zoom_value" format="float" type="dimen">14.0</item>
4+
<item name="padding_ratio" format="float" type="dimen">1.3</item>
55
</resources>

android/canonical/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
<string name="working">Started</string>
1010
<string name="stopped">Stopped</string>
1111
<string name="my_location_title">My location</string>
12+
<string name="cannot_access_location">Cannot access location now. Please Try later</string>
1213
</resources>

0 commit comments

Comments
 (0)