0
votes

I have an SQLITE database that stores the coordinates of places as float numbers.

PLACE TABLE
--------------------------------
placeID  | latitude | longitude
--------------------------------
1        | XX.XXXXXX| YY.YYYYYY
2        | X1.XXXXXX| Y1.YYYYYY

Let's say that I'm standing in a place with specific coordinates (lat and lon).

I would like to find all the places 1km around me (in a circle).

1) How can I convert the meters to coordinates?

2) How can I get from the database all the places 1km away from me? Cause I would like to add the meters to the coordinates.

Is that possible?

Thanks, in advance

1
How many entries will be in the dbAlexWien
Many entries about 300programmer
300 is nothing, simply read all entries into main Memory (e.g in , List, Array) at start of app. etc. Then do a brute force search.AlexWien

1 Answers

2
votes

Simply use the distanceTo() or distanceBetween(lat1, lon1, lat2, lon2) function of your API.
If you dont have such a method, then search for haversine formula.

Then the location are within a cirlcle of x meters around you if the distance from you to the object is <= x.

In code:

double radius = 1000; // 1 km
double distanceMeters = haversineDistance(mylat, mylon, otherLat, otherLon);
if (distanceeMeters <= radius) {
  // other location (otherLat, otherfLOn) is inside of radius of 1km
}