获取谷歌地图的准确位置 [英] Get google map accurate location

查看:74
本文介绍了获取谷歌地图的准确位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可返回用户当前位置,但是位置不正确

I have following code which return user current location, but the location is not accurate

lateinit var mFusedLocationClient: FusedLocationProviderClient

override fun onCreateView(...) {....}

    @SuppressLint("MissingPermission")
    private fun getLastLocation() {
        mFusedLocationClient.lastLocation
            .addOnCompleteListener(requireActivity()) { task ->
                if (task.isSuccessful && task.result != null) {
                    mLastLocation = task.result
                    mMap.isMyLocationEnabled = true
                    val driverLatLng = LatLng(mLastLocation.latitude, mLastLocation.longitude)
                    markerOptions.position(driverLatLng).title("Your location").icon(
                        BitmapDescriptorFactory.fromBitmap(
                            driverIcon()
                        )
                    )
                    mMap.addMarker(markerOptions)
                } else {
                    Log.w("location", "getLastLocation:exception", task.exception)
                }
            }
    }

问题

  1. 如何使当前位置更准确
  2. 如何使蓝色圆圈更小,以仅覆盖当前位置的图钉(标记)?

推荐答案

问题1)

如果您不希望获得最高的准确性,则需要将其设置为以下值:

If you are not requesting the highest accuracy possible you need to set it to this value:

LocationRequest.PRIORITY_HIGH_ACCURACY

通过这种方式,提供商应使用设备GPS(如果有)代替Wi-Fi/蜂窝塔. 官方文档此处.可以找到

This way the provider should use the device GPS if available instead of Wi-Fi/cell towers. Official docs here. A code sample using high accuracy can be found here.

问题2)

如果我对您的问题的回答正确,则圆圈代表当前位置的精度,因此,如果精度更高,则我认为圆圈会变小.您只需尝试以尽可能最高的精度进行尝试(只需确保正在使用设备的GPS且信号良好即可)

If I got your question right the circle represents the accuracy of the current location so with a higher precision the circle I suppose that the circle would become smaller. You just have to give it a try with the highest possible accuracy (just be sure that the device's GPS is being used and that it has a good signal)

这篇关于获取谷歌地图的准确位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆