package com.base.locationsharewhite.ui.main

import android.annotation.SuppressLint
import android.app.Activity
import android.location.Location
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.model.LatLng

class MainPresenter(
    val activity: Activity
) {

    //google的地理位置服务
    private var fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(activity)
    var googleLocation: LatLng? = null

    var locationCallBack: ((latLng: LatLng) -> Unit)? = null
    @SuppressLint("MissingPermission")
    fun getGoogleServiceLocation() {
        fusedLocationClient.lastLocation
            .addOnSuccessListener { location: Location? ->
                if (location != null) {
                    val latLng = LatLng(location.latitude, location.longitude)
                    googleLocation = latLng
                    locationCallBack?.invoke(latLng)
                }
            }
    }
}