Making Nearby locations load faster
See original GitHub issueSummary:
Problem :
There is a significant lag in the loading of nearby locations ( about 3-4 seconds in normal network conditions).
This may be due to two reasons :
- Time interval in getting the location information from device
- Time interval in getting the desired number of nearby locations from api
Proposed Solution :
The solution to 1st problem may be to use the FusedLocationApi to immediately get the last known location. And for the second problem is to make the nearby locations to load asynchronously in the background as and when the nearby locations are loaded one by one and update the Recycler Views in the UI.
Screencast
Code
I saw this code snippet in NearbyPlaces which gets the nearby location places by querying wikidata. We can asynchronously do this and update the Recycler views in the UI to quickly display the loaded results first by using the notifydataset() function. This may provide faster results to the user.
try {
// increase the radius gradually to find a satisfactory number of nearby places
while (radius <= MAX_RADIUS) {
places = getFromWikidataQuery(curLatLng, lang, radius);
Timber.d("%d results at radius: %f", places.size(), radius);
if (places.size() >= MIN_RESULTS) {
break;
} else {
radius *= RADIUS_MULTIPLIER;
}
}
}
Device and Android version: Android 6.0.1
Commons app version: 2.6.7-debug-master
Would you like to work on the issue?
Yes
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (7 by maintainers)
Top GitHub Comments
The algorithm steps outward and performs multiple queries. If it updated the GUI each time it received data then you would start seeing results quicker - you’d see the circle of map pins expand - in a series of steps. Your’re right that each query takes a while before showing results, but, there’s no point forcing the user to sit there if we do have usable data to give them.
@HaricharanDharmaji There is a server-side timeout (I believe it is 30 seconds or one minute) which is probably why Nearby just loads nothing sometimes.
Would you mind watching the output of
adb logcat
when loading Nearby? You might spot things that might help the project progress. Thanks! 😃