1

Scenario: We have about well over 10k+ rows of data with spatial attributes of latitudes and longitudes. We would like to sort and fetch the object(around 300) closest to my current location.

What has been done: Created OrmLite Object Table that stores all the rows with lat and long being double. Currently calling queryForAll and using Comparable interface (distanceTo) to sort the data in order of distance from current location.

Problem: The above solution is highly inefficient as number of rows increases beyond 10K+, it takes long time to perform the sort operation.

Question: a. Is there a way to handle Spatial data in Ormlite or even adding Android Location as a column? b. Can we call raw query that gives list of objects, I would prefer this approach as the sorting takes place while querying itself.

3
  • 2
    It's generally not a good practice to ever do a query for an entire table, on any platform. It kind of defeats the purpose of a database. If you want the rows near a given location, write a query that searches for points with latitude/longitude in the correct range. Mar 30, 2013 at 5:38
  • Thanks I will definitely be using it to reduce the number of rows. However any other options for ORMLite?
    – PravinCG
    Mar 30, 2013 at 12:32
  • Its not matter of ORMLite but its the matter of database engine itself. So your questions should point to the sqlite which is used in Android. You are probably looking for something similar to PostGIS used for Postgres however such features are not available in sqlite. My suggestions are: 1) use remote server with PostGIS OR 2) find objects by location range.
    – Martin Nuc
    Apr 9, 2013 at 10:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.