how to detect change of zoom or location on mapview

Dear Expert:

I'm createing an iPhone application which shows restaurants from our database. Now we are adding all annotations of restaurants on map. To improve performance, we want to add all the marks that fits inside the map, however, we need to call the function that fills this marks every time that user changes the zoom level on the map or every time user moves the map.

How can we detect when user changes the view of the map ?

Thank you.
LVL 15
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Detecting when the user zooms or moves the map is actually the easy part of your problem.
The MKMapView has a delegate method which you can use for this:


But in my opinion you'll have a bigger problem on your hands. I recently worked on a project with thousands of locations, stored in complex ManagedObjects, all located in a rather small area, if too much annotations were on the screen at once the ones close together had to be clustered together. When zooming out annotations had to be clustered together but when zooming in the visible annotations always had to stay visible, so the filtering function always had to start from the current state of the map.
Now I don't know how many restaurants you have in your database and over what area they're spread but chances are unless you're working with very little data that performing a fetchRequest for the visible restaurants every time the regionDidChanged method gets called probably won't be an option. In my case that was the huge performance killer and I had to resort to keeping all ManagedObjects in memory and filter from there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gplanaAuthor Commented:
Excellent. This is exactly what I needed.

Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.