首页 > 解决方案 > 尝试获取当前位置时出现 Surface 和 Nativecrypto 错误

问题描述

我收到错误:

E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7fc080e0
E/NativeCrypto: ssl=0x7f5ec8fc00 cert_verify_callback x509_store_ctx=0x7f5d8f0270 arg=0x0
E/NativeCrypto: ssl=0x7f5ec8fc00 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA
E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport

尝试在 kotlin android 中获取当前位置时。

我尝试使用 android 6 和 8,仍然出现错误,我无法在地图上获取当前位置,打开一张空白地图

谁能帮我解决这里的问题,我从几天开始就被这个问题困扰?

这是我获取当前地图位置的代码:

class MapActivity : FragmentActivity(), OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener,com.google.android.gms.location.LocationListener {
    private var service: LocationManager? = null
    private var enabled: Boolean? = null
    private var mCurrLocationMarker: Marker? = null
    private lateinit var mMap: GoogleMap
    private lateinit var mGoogleApiClient:GoogleApiClient
    private lateinit var mLastLocation:Location

    private lateinit var mLocationRequest:LocationRequest

    override fun onLocationChanged(location: Location) {

        mLastLocation = location
        val latLng=LatLng(location.latitude,location.longitude)

        val markerOptions = MarkerOptions()
        markerOptions.position(latLng)
        markerOptions.title("Current Position")
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA))
        mCurrLocationMarker = mMap.addMarker(markerOptions)
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f))

    }
    override fun onConnected(bundle: Bundle?) {
        Log.d("sasas:","im here")

        mLocationRequest=LocationRequest()
        mLocationRequest.interval = 1000
        mLocationRequest.fastestInterval = 1000
        mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY

        if (!enabled!!) {
            val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        // Check if permission is granted or not
        if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this)
        }
//        LocationServices.getFusedLocationProviderClient(this)
    }
    override fun onConnectionSuspended(p0: Int) {

    }

    override fun onConnectionFailed(p0: ConnectionResult) {

    }

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_map)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        service = this.getSystemService(LOCATION_SERVICE) as LocationManager
        enabled = service!!.isProviderEnabled(LocationManager.GPS_PROVIDER)
        val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)
    }


    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap
        mMap.mapType = GoogleMap.MAP_TYPE_NORMAL
        if (ActivityCompat.checkSelfPermission
                (this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return
        }
        buildGoogleApiClient()
        mMap.isMyLocationEnabled = true

    }
    @Synchronized
    fun buildGoogleApiClient(){
        mGoogleApiClient = GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build()
        mGoogleApiClient.connect()
    }

    }

上面的代码有什么问题,或者为什么会出现这些错误以及为什么显示空白地图而不是显示当前位置?

标签: androidkotlinkotlin-android-extensionscreate-react-kotlin-app

解决方案


推荐阅读