Clicky

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.

asked 12/08/2011 02:01

gplana's gravatar image

gplana ♦♦


2 Answers:
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:
mapView:regionDidChangeAnimated:

See:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html


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.




link

answered

Snapples's gravatar image

Snapples

Excellent. This is exactly what I needed.

Thank you.
link

answered 2011-12-10 at 14:20:24

gplana's gravatar image

gplana

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×21
×42

Asked: 12/08/2011 02:01

Seen: 244 times

Last updated: 12/10/2011 08:32