我有一个带有Google Places API和Google Maps API的应用程序。用户可以拿起地方,稍后再在MapView上打开。经过一些测试,我发现FusedLocationProviderClient不能按预期在所有设备上运行。它在Android 8.1(Redmi Note 5)上运行良好,但在5.1(Meizu m3 note)上却无法正常运行。 5.1中的问题是LocationCallbackListener永远不会被调用。 这是代码:
override fun onMapReady(googleMap: GoogleMap?) {
mGoogleMap = googleMap
mLocationRequest.interval = 60000
mLocationRequest.fastestInterval = 60000
mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity())
mLocationCallback = LocationCallbackListener()
val placeLatLng = LatLng(mPlaceLatLng.first, mPlaceLatLng.second)
mGoogleMap?.addMarker(MarkerOptions().position(placeLatLng).title(mPlaceName).snippet(mPlaceAddress))
mGoogleMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(placeLatLng, 15.0f))
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
//Location Permission already granted
mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
mGoogleMap?.isMyLocationEnabled = true
} else {
PermissionHelper.checkFineLocationPermission(requireActivity())
}
} else {
mFusedLocationClient?.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
mGoogleMap?.isMyLocationEnabled = true
}
}
我有一个
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
在我的清单上。
GooglePlaces API也未显示设备位置。所以,我想我无法访问任何API中的位置