0

I have a sqlite database with about 100 000 rows containing longitudes and latitudes of ATMs. I want to display this ATMs by pins on MKMapView. But I think that it is not good for memory and not o fast if I will load all coordinates from DB at once. What is the best way to do it?

Siarhei Fedartsou
  • 1,843
  • 6
  • 30
  • 44

1 Answers1

3

You're absolutely right, don't load them all at once!

Use a bounding box to only get coordinates that are within the map your want to display. Check out the answer to this question : Core Data and Core Location

Use the same concept of a upper and lower limit to your lat and lng to only return rows from sqlite that are currently visible. Your query would look something like

SELECT * FROM atms WHERE lat > 51.4 and lat < 51.6 and lng > -0.165 and lng < -0.175

This query only returns ATMs that are near central London (51.5, -0.17).

Community
  • 1
  • 1
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • thx. But if I will execute new query to sqlite every time when user is draggin MKMapView it will not so fast. Am I right? – Siarhei Fedartsou Aug 18 '11 at 08:44
  • 1
    You could to wait until the map has been dragged a certain distance? Or wait until the user has finished dragging before running the new query? – deanWombourne Aug 18 '11 at 09:25
  • But I want to do it without any delay. Immediately. Is it realizable? – Siarhei Fedartsou Aug 18 '11 at 11:49
  • Make your bounding box larger than the map - this means that if they drag a bit there are still markers that will scroll into view. While that's happening, you are running the next query in the background to get more markers. But you can't have everything you want - it's either fast or it uses less memory. You have to choose which. – deanWombourne Aug 18 '11 at 12:52