I'm trying to use Localbroadcast to send latitude and longitude over to the main activity. But the parameter of this
within getInstance()
isn't working. I tried adding the context class but it is still wrong. Any ideas? Thanks.
companion object {
val TAG = "LocationTrackingService"
val INTERVAL = 5000.toLong() // In milliseconds
val DISTANCE = 0.toFloat() // In meters
val locationListeners = arrayOf(
LTRLocationListener(LocationManager.GPS_PROVIDER),
LTRLocationListener(LocationManager.NETWORK_PROVIDER)
)
private fun sendRequest() {
// The string "GPS_not_activaded" will be used to filer the intent
val intentRequest = Intent("Sending_location_coordinates")
LocalBroadcastManager.getInstance(this).sendBroadcast(intentRequest)
Log.d(TAG,"Se enviaron las coordenadas")
}
class LTRLocationListener(provider: String) : android.location.LocationListener {
val lastLocation = Location(provider)
override fun onLocationChanged(location: Location?) {
lastLocation.set(location)
Log.d(TAG, "======================= New Data =======================")
Log.d(TAG,"latitud: "+ lastLocation.latitude)
Log.d(TAG,"longitud: "+ lastLocation.longitude)
sendRequest()
}