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.
LocationRequest.Builder works with 1 or 2 parameters.
This is the code that worked for me :
mLocationRequest = new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 1000)
.setWaitForAccurateLocation(false)
.setMinUpdateIntervalMillis(500)
.setMaxUpdateDelayMillis(1000)
.build();
in my case i was importing wrong file.
this is right file "import com.google.android.gms.location.LocationRequest;"