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)

 

你可能感兴趣的:(android 高德地图 定位蓝点不显示)