Skip to main content

Location

With location library you can access current location, observer current location and get place or address of current and specified location (search).

Download#

implementation 'com.utsman.geolib:location:{last_version}'

Prerequisite class#

You need FusedLocationProviderClient

val fusedLocation = LocationServices.getFusedLocationProviderClient(context)

Create PlaceLocation#

val placesLocation = fusedLocation.createPlacesLocation(HERE_API_KEY)

Current location#

Observer current location#

This function build under CoroutineScope with return Flow

MainScope().launch {
// start observer location
placesLocation.getLocationFlow()
.collect { location ->
// location result
}
}

Get current location#

MainScope().launch {
val location = placesLocation.getLocationFlow().first()
}

Get comparator current location (prev and current)#

MainScope().launch {
placesLocation.getComparisonLocation()
.collect { comparisonLocation ->
val prevLocation = comparisonLocation.previousLocation
val currentLocation = comparisonLocation.currentLocation
}
}

Place Location#

Structure class of PlaceData#

Paramtypedesc
hereIdStringId place from Here API
titleStringTitle of place
addressStringAddress of place
districtStringDistrict of place
cityStringCity of place
locationLocationLocation of place
distanceDoubleDistance of current location and place
categoryString nullableCategory of place

Get place from location#

val result: Result<List<PlaceData>> = placesLocation.getPlacesLocation(location)
result.doOnSuccess { places ->
// handle success
}
result.doOnFailure {
// handler failure
}

Search nearby place#

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
}