Map SDK for Androidで地図を表示し、現在地の取得は出来ているのですが、初期状態でカメラを現在地に合わせることが出来ません。

moveCamera(CameraUpdateFactory.newLatLngZoomでカメラの初期の位置は設定できることを知ったのですが、緯度経度を現在地にするにはどうすれば良いのでしょうか。

コード

mapSampleFragment.kt

class MapSampleFragment : Fragment(), OnMapReadyCallback, Location.OnLocationResultListener {

    private lateinit var map: GoogleMap
    private var location: Location? = null

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_map_sample, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // TODO ①パーミッションの確認
        if (ContextCompat.checkSelfPermission(
                requireContext(),
                Manifest.permission.ACCESS_FINE_LOCATION
            ) == PackageManager.PERMISSION_GRANTED) {

            // パーミッションの許可されていた場合のみ、パーミッションを許可して
            location?.startLocationUpdates()

            val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
            mapFragment.getMapAsync(this)
        } else {
            // パーミッション未許可
            requestLocationPermission()
        }
    }

    override fun onResume() {
        super.onResume()
        // 位置情報の取得を行えるよう、Locationクラスを作成しておきます。
        location = Location(requireContext(), this)
    }

    override fun onPause() {
        super.onPause()
        // アプリを閉じた後も不要に位置情報を取得しないよう、このタイミングで処理を止めます。
        location?.stopLocationUpdates()
    }

    override fun onMapReady(googleMap: GoogleMap) {
        // Mapの初期化に成功した場合に呼び出されます。
        map = googleMap.apply {
            uiSettings.isScrollGesturesEnabled = true
            uiSettings.isZoomControlsEnabled = true
            uiSettings.isZoomGesturesEnabled = true
            uiSettings.isRotateGesturesEnabled = true
            isMyLocationEnabled = true
            uiSettings.isMyLocationButtonEnabled = true
        }
    }

    override fun onLocationResult(locationResult: LocationResult?) {
        // TODO ③位置情報の取得とMap更新
        locationResult?.let {
            map.moveCamera(
                CameraUpdateFactory.newLatLngZoom(
                    LatLng(
                        it.lastLocation.latitude,
                        it.lastLocation.longitude
                    ), DEFAULT_ZOOM_LEVEL
                )
            )
        }
    }

    override fun onLocationError() {
        // TODO 位置情報の取得に失敗した場合に表示の制御をこちらで行います。
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultlocation, DEFAULT_ZOOM_LEVEL))
    }

    override fun onRequestPermissionsResult(
        requestCode: Int, permissions: Array<String>, grantResults: IntArray
    ) {
        // TODO ②マップの初期化
        if (requestCode != ACCESS_FINE_LOCATION_REQUEST_CODE) {
            return
        }

        // android.permission.ACCESS_FINE_LOCATION が許可された
        if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            location?.startLocationUpdates()

            val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
            mapFragment.getMapAsync(this)
        } else {
            // TODO  位置情報取得を拒否された場合に表示する処理をここに記載します。
        }
    }

    // 位置情報パーミッシンのリクエスト
    private fun requestLocationPermission() {
        // 権限チェックした結果、許可されていない場合はダイアログを出す
        if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
            requestPermissions(
                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                ACCESS_FINE_LOCATION_REQUEST_CODE)
        } else {
            requestPermissions(
                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                ACCESS_FINE_LOCATION_REQUEST_CODE)

        }
    }

    companion object {
        private const val ACCESS_FINE_LOCATION_REQUEST_CODE = 1000
        private const val DEFAULT_ZOOM_LEVEL = 13.5f
        private val defaultlocation = LatLng(26.2125225, 127.6785822)
    }
}

#android

【Map SDK for Android】地図の初期表示位置を現在地にしたい|teratail
7.40 GEEK