How to sort a Map of LatLng,String by the order of values in an ArrayList of LatLng

Ross Hayden :

Let's say I have a HashMap of Latitude/Longitudes + Names associated, and a separate ArrayList of the same Latitude/Longitudes that have been sorted by the nearest to my current location. How to I sort the HashMap to be in the same order as the ArrayList. If this is too complex then is there away to sort the initial HashMap by the nearest Latitude/Longitudes?

Erfan Moharramkhani :

I think it is better to use LinkedHashMap (a Map that has order).

You can create a new LinkedHashMap and insert Latitude/Longitudes to it based on the ArrayList that you have (sorted list). Remember LinkedHashMap is ordered based on the insertion.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31413&siteId=1