Kotlin,北斗卫星,定位

***
private fun initLocation() {
        var manager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.ACCESS_FINE_LOCATION
                ) != PackageManager.PERMISSION_GRANTED
            ) {
                return
            }
            manager.registerGnssStatusCallback(LocalCallback())
        }
        manager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            1000,
            1F,
            object : LocationListener {
                override fun onLocationChanged(location: Location) {
                    Log.e(
                        "是不是北斗----------",
                        "1289" + location.latitude + "---" + location.longitude
                    )
                }
                override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
                    super.onStatusChanged(provider, status, extras)
                }
                override fun onProviderEnabled(provider: String) {
                    super.onProviderEnabled(provider)
                }
                override fun onProviderDisabled(provider: String) {
                    super.onProviderDisabled(provider)
                }
            })
    }
另一个接口:
package com.allynav.rtk.farm.service
import android.location.GnssStatus
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.N)
class LocalCallback : GnssStatus.Callback() {
    override fun onStarted() {
        super.onStarted()
    }
    override fun onStopped() {
        super.onStopped()
    }
    override fun onSatelliteStatusChanged(status: GnssStatus) {
        super.onSatelliteStatusChanged(status)
        var satelliteCount = status.satelliteCount;
        makeGnssStatus(status,satelliteCount)
    }
    fun makeGnssStatus(status: GnssStatus, satelliteCount: Int) {
        if (satelliteCount > 0) {
            for (i in 0 until satelliteCount) {
                var type = status.getConstellationType(i);
                if (GnssStatus.CONSTELLATION_BEIDOU == type) {
                    Log.e("是不是北斗","1289" + "provider")
                }
            }
        }
    }
}

你可能感兴趣的:(安卓,kotlin,android,java)