I’m working on Google Maps, and I’ve managed to place about 73 pinpoint from sqllite DB on the map which they present a places for stores in the current user city.
Now I have to show only the closet five places to user not all the 73 place.Does any one have an idea or a solution for this.
First, calculate distances between user location and all places.
To get user location read this guide Location strategies
Create a class for your place with a method to calculate a distance between it and user location:
Here,
distanceTomethod was called: read about distanceToNow, create
Place[]array and initialize it with all your places from database. For each place callcalculateDistancemethod.After that, sort your array using
Arrays.sort( Arrays.sort )Show on the map only first five places from your array
Done!