Last active
August 14, 2020 14:47
-
-
Save yektasarioglu/0385da377fb49bf07c6346d64e658fbf to your computer and use it in GitHub Desktop.
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
private inline fun addNearbyHospitals(radius: Float, crossinline onEnd: (nearbyHealthInstitutions: List<Site>) -> Unit) { | |
if (siteKitManager == null) return | |
val nearbyHealthInstitutions = mutableListOf<Site>() | |
for (i in 1..SiteKitManager.MAX_PAGE_INDEX) { | |
Log.i(TAG, "i is $i") | |
if (siteKitManager!!.isInTheRangeOfMaxResult(pageIndex = i, pageSize = 20)) | |
siteKitManager?.searchNearby( | |
location = Coordinate( | |
userLocation?.coordinate?.first!!, | |
userLocation?.coordinate?.second!! | |
), | |
radius = radius, | |
searchLanguage = "en", | |
locationType = LocationType.HOSPITAL, | |
pageFilters = i to 20, | |
searchResultListener = object : SearchResultListener<NearbySearchResponse?> { | |
override fun onSearchResult(results: NearbySearchResponse?) { | |
Log.i("TAG", "Total result count is ${results?.totalCount}") | |
val sites = results!!.sites | |
if (results.totalCount <= 0 || sites == null || sites.size <= 0) | |
return | |
for (site in sites) { | |
Log.i("TAG", "siteId: ${site.siteId}, name: ${site.name}, distance: ${site.distance} address: ${site.address} \r\n") | |
} | |
nearbyHealthInstitutions.addAll(sites) | |
if (nearbyHealthInstitutions.size == SiteKitManager.MAX_RESULT) | |
onEnd(nearbyHealthInstitutions) | |
} | |
override fun onSearchError(status: SearchStatus) { | |
Log.i("TAG", "Error : " + status.errorCode + " " + status.errorMessage) | |
} | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment