Search code examples
androidalgorithmsqlitegeolocationlocation

getting certain location points from a database


I'm creating an Android application that needs to find all the points within a given radius of the device. However these locations will be stored in a database either SQL (on a server) or SQLite (for early testing/demo), what I dont want to do is get all the locations and filter down on the device as the could potentially be thousands of points. The locations are stored as two separate fields for latitude and longitude, how could I get only the points from the database that are within a certain radius of a location?


Solution

  • Use a conceptual bounding box around the circle large enough to contain all points on the circle.

    For example, a simple box that might work for you:

    Assuming the center of the circle is 100,100 with radus 5, you download all points within the box (95,95) (105,105)

    Then on the client you can do necessary calculations to determine which subset of points are in your circle