I get this error when I run the code below:
None of the following functions can be called with the arguments supplied:
public constructor FusedLocationProviderClient(p0: Activity) defined in com.google.android.gms.location.FusedLocationProviderClient
public constructor FusedLocationProviderClient(p0: Context) defined in com.google.android.gms.location.FusedLocationProviderClient
Code:
import android.location.Location
import android.os.Build
import android.os.SystemClock
import com.google.android.gms.location.FusedLocationProviderClient
class startMockLocation {
fun main() {
var locationProvider = FusedLocationProviderClient() // I GET THE ERROR HERE
locationProvider.setMockMode(true)
val loc = Location("gps")
val mockLocation = Location("gps") // a string
mockLocation.latitude = 48.8566 // double
mockLocation.longitude = 2.3522
mockLocation.altitude = loc.altitude
mockLocation.time = System.currentTimeMillis()
mockLocation.accuracy = 1f
mockLocation.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mockLocation.bearingAccuracyDegrees = 0.1f
mockLocation.verticalAccuracyMeters = 0.1f
mockLocation.speedAccuracyMetersPerSecond = 0.01f
}
// locationManager.setTestProviderLocation(providerName, mockLocation)
locationProvider.setMockLocation(mockLocation)
}
}
How can I fix this error? I simply want to set the device's location to the given coordinates. I also get more issues but this is the main error.