-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carlos Olimpio
committed
Nov 5, 2019
1 parent
3887baa
commit d889207
Showing
9 changed files
with
108 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/discordtime/gpts/maps/viewmodel/LocationListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.discordtime.gpts.maps.viewmodel | ||
|
||
import android.location.Location | ||
|
||
interface LocationListener { | ||
|
||
fun onLocationChanged(location: Location) | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/discordtime/gpts/maps/viewmodel/LocationManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.discordtime.gpts.maps.viewmodel | ||
|
||
import android.content.Context | ||
import android.location.Location | ||
import android.os.Looper | ||
import com.google.android.gms.location.* | ||
|
||
class LocationManager(val mContext: Context, private val locationListener: LocationListener) { | ||
|
||
private val UPDATE_INTERVAL: Long = 2 * 60 * 1000 //2 mins | ||
private val FASTEST_INTERVAL: Long = 40 * 1000 //40 segs | ||
|
||
private val mLocationRequest = LocationRequest() | ||
private lateinit var mFusedLocationProviderClient: FusedLocationProviderClient | ||
|
||
fun startLocationUpdates() { | ||
//updates properties | ||
mLocationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY | ||
mLocationRequest.interval = UPDATE_INTERVAL | ||
mLocationRequest.fastestInterval = FASTEST_INTERVAL | ||
|
||
var builder = LocationSettingsRequest.Builder() | ||
builder.addLocationRequest(mLocationRequest) | ||
var locationSettingsRequest = builder.build() | ||
|
||
//checks if location settings are satisfied | ||
var settingsClient = LocationServices.getSettingsClient(mContext) | ||
settingsClient.checkLocationSettings(locationSettingsRequest) | ||
|
||
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(mContext) | ||
mFusedLocationProviderClient.requestLocationUpdates(mLocationRequest, object : LocationCallback() { | ||
override fun onLocationResult(locationResult: LocationResult?) { | ||
onLocationChanged() | ||
} | ||
|
||
}, Looper.myLooper()) | ||
} | ||
|
||
private fun onLocationChanged() { | ||
//var msg = "location changed: " + location?.latitude + ", " + location?.longitude | ||
//Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show() | ||
|
||
mFusedLocationProviderClient.lastLocation.addOnSuccessListener { location: Location -> | ||
locationListener.onLocationChanged(location) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters