I haven't used location services in a long, long time, so I'm just looking at the documentation for 'LocationRequest.Builder` and guessing at your equivalent code because it looks self-explanatory. Builders are a common pattern, used more often in Java-based APIs like this one than they are used in pure-Kotlin APIs. You can look up "java builder pattern" to read about it.
private fun NewLocation() {
val locationRequest = LocationRequest.Builder()
.setPriority(Priority.PRIORITY_HIGH_ACCURACY)
.setIntervalMillis(0L)
.setMinUpdateIntervalMillis(0L)
.setMaxUpdates(1)
.build()
mfusedlocation = LocationServices.getFusedLocationProviderClient(this)
mfusedlocation.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper())
}
FYI since you're working on a portfolio:
Function names in Kotlin start with a verb and lower-case letter by convention. Or if it returns a modified copy of an object, you can use a past participle instead of a phrase starting with a verb. For example, I would rename
NewLocation()to something likebeginLocationRequest().The
mSomethingpattern of naming variables (putting abbreviations in front of variable names) is called Hungarian notation.mstands for "member", but Kotlin properties are not even called member variables. I've never seen Hungarian notation used in Kotlin before, and it is rarely used in Java. It is widely regarded as making code less readable, especially with modern IDEs. I would advise against using it in a portfolio project as it is more likely to damage the impression you want to give than it is to help, especially if you are using it inconsistently.
Videos
LocationRequest locationRequest =
new LocationRequest.Builder(
LocationRequest.PRIORITY_HIGH_ACCURACY,
10000
).build();
locationRequest.setFastestInterval(5000);
locationRequest = new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 100)
.setIntervalMillis(INTERVAL_MILLIS) // Sets the interval for location updates
.setMinUpdateIntervalMillis(INTERVAL_MILLIS/2) // Sets the fastest allowed interval of location updates.
.setWaitForAccurateLocation(false) // Want Accurate location updates make it true or you get approximate updates
.setMaxUpdateDelayMillis(100) // Sets the longest a location update may be delayed.
.build();