Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 27
Registered: ‎07-26-2012
My Device: i dont have a blackberry device
My Carrier: i dont have a blackberry device

Sort List By Nearest Location Geolocation

Hi, Everybody

i want to create a listview that sorted by nearest location from my phone using geolocation

i already create a list and has a longitude and latitide inside them, but i dont know how to sort it from nearest place from me


can someone give me idea how to do this on blackberry java ?

any idea or suggestion are very usefull to me

thanks in advance

best regards,
aditya eka putra (@abang_adit)
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Sort List By Nearest Location Geolocation

You say 'ListView' - are you developing in QML and BB 10.  There is no ListView in BBOS but there is in BB10.


However both BBOS and BB10 'co-ordinate' class have a distance function that will provide you with the distance from one coordinate to another.  So in both you can calculate how far away from a point a location you have actually is.  Then you can just sort using this value.


Look at the API documentation in both cases to find out how to do this. 


Regarding sorting, in addition to just coding your own, in BB Java there are various Sorted collections - just follow the API documention for the classes that implement SortableCollection.  And there is the SimpleSortingVector.