-
-
Notifications
You must be signed in to change notification settings - Fork 15
Location
Muhammad Utsman edited this page Jul 25, 2021
·
1 revision
With location library you can access current location, observer current location and get place or address of current and specified location (search).
implementation 'io.github.utsmannn:geolib-location:{last_version}'
You need FusedLocationProviderClient
val fusedLocation = LocationServices.getFusedLocationProviderClient(context)
val placesLocation = fusedLocation.createPlacesLocation(HERE_API_KEY)
This function build under CoroutineScope
with return Flow
MainScope().launch {
// start observer location
placesLocation.getLocationFlow()
.collect { location ->
// location result
}
}
MainScope().launch {
val location = placesLocation.getLocationFlow().first()
}
MainScope().launch {
placesLocation.getComparisonLocation()
.collect { comparisonLocation ->
val prevLocation = comparisonLocation.previousLocation
val currentLocation = comparisonLocation.currentLocation
}
}
Param | type | desc |
---|---|---|
hereId |
String |
Id place from Here API |
title |
String |
Title of place |
address |
String |
Address of place |
district |
String |
District of place |
city |
String |
City of place |
location |
Location |
Location of place |
distance |
Double |
Distance of current location and place |
category |
String nullable |
Category of place |
val result: Result<List<PlaceData>> = placesLocation.getPlacesLocation(location)
result.doOnSuccess { places ->
// handle success
}
result.doOnFailure {
// handler failure
}
Search place is searching nearby place on location by query with data result List<PlaceData>
val result: Result<List<PlaceData>> = placesLocation.searchPlaces(location, query)
result.doOnSuccess { places ->
// handle success
}
result.doOnFailure {
// handler failure
}