android 高德地图 定位蓝点不显示

照官方文档的写法:

         MyLocationStyle().apply {
            interval(2000)
            showMyLocation(true)
             aMap.myLocationStyle = this
             aMap.isMyLocationEnabled = true
        }

写完后发现蓝点没出来,看遍文档也没发现原因,最后回去查看去年写的代码,发现要显示定位蓝点,需要  ACCESS_FINE_LOCATION 权限

另外,还需要判断gps有没有打开,没有的话需要引导用户打开gps

    //判断gps是否打开
    fun isOpenGps():Boolean =  (context.getSystemService(Context.LOCATION_SERVICE) as LocationManager)
        .run {
            isProviderEnabled(LocationManager.GPS_PROVIDER)
        }
    //跳转到打开gps设置页面
    fun openGPSSetting(activity:Activity,requestCode:Int) = activity.startActivityForResult(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),requestCode)
    fun openGPSSetting(fragment:Fragment,requestCode:Int) = fragment.startActivityForResult(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),requestCode)

猜你喜欢

转载自blog.csdn.net/jingzz1/article/details/107434303
今日推荐