Reputation: 2414
I am developing a POI locator app. I am parsing a JSON file with over 1600 locations. How would effiecntly compare this list to the current users location and get the closest 10?
EDIT The app is using no server, as I want to use local JSON files.
Upvotes: 1
Views: 355
Reputation: 2414
I fixed it by using a for loop and measuring the distance between the location and the users location.
distance = locationA.distanceTo(locationB);
if (distance <= 1000 * 10) //finding all within 10km Radius.{
ADD GEOPOINT HERE
}
Upvotes: 1
Reputation: 1368
We were writing this kind of app as well, and performed some performance tests on MySQL and MongoDB. Because MongoDB is document based and stores its data in json format, location based queries(like closest restaurants to the user) completes and returns incredibly fast. As far as I can remember, it was approximately 10 times faster than MySQL. So, even if your application doesn' t currently use a no-sql database, I strongly suggest you to use MongoDB even just for location calculating part of your project.
Upvotes: 0
Reputation: 993
If you are going to find distance by a birds-view approach you can just query your locations and check distance with formula located here. But if you are going to take roads (graphs) into accounts, I'm afraid you'll need to use some kind of pathfinding service like google maps or roll your own. (As far as I know there is no built-in mechanism in Android.)
Upvotes: 0
Reputation: 29121
It's better if you can store the 1600 locations in a database(like mongodb) which supports geo spatial queries. you can directly query over the database to determine the closest N no.of locations to the given latitude and longitude of the user.
Upvotes: 0