Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimization for MKAnnotations and Core Data
    primarykey
    data
    text
    <p>I have some locations ( in this case >3000 ) stored with Core Data. Once I open the map, I fetch the locations and store them in an array. Each time the mapview region is changed I call a function which will calculate which annotations are visible in the current <code>visibleMaprect</code> and filter them by pixel-distance. ( I know there would be more complex optimizations, like quadtrees, but I would not really implement it right now, if it's not extremely necessary ). This is my code : </p> <pre><code>//locations is an array of NSManagedObjects for (int i =0 ; i &lt; [locations count]; i++) { // managed object class for faster access, valueforkey takes ages ... LocationEntity * thisLocation = [locations objectAtIndex:i]; CLLocationCoordinate2D coord = CLLocationCoordinate2DMake( [thisLocation.latitude doubleValue], [thisLocation.longitude doubleValue]) ; // mapRect is mapView.visibleMapRect BOOL isOnScreen = MKMapRectContainsPoint(mapRect, MKMapPointForCoordinate(coord)); if (isOnScreen) { CGPoint cgp = [mapView convertCoordinate:coord toPointToView:mapView]; // compare the distance to already existing annotations for (int idx = 0; idx &lt; [annotations count] &amp;&amp; hasEnoughDistance; idx++) { CGPoint cgp_prev = [mapView convertCoordinate:[[annotations objectAtIndex:idx] coordinate] toPointToView:mapView]; if ( getDist(cgp, cgp_prev) &lt; dist ) hasEnoughDistance = FALSE; } } if (hasEnoughDistance) // if it's ok, create the annotation, add to an array and after the for add all to the map } </code></pre> <p>The map is freezing for a few seconds after each zoom/movement. I checked with time profiler and the simple obtainment of coordinates is taking sometimes 1 whole second, sometimes just 0.1, even though the coordinates are indexed attributes in my model... Also these type of lines seem to take ages : <code>CGPoint cgp = [mapView convertCoordinate:coord toPointToView:mapView];</code> </p> <p>Any suggestions how could I calculate the pixel/point distance between two annotations/coordinates without going through this function ? Or any optimization suggestions for Core Data? </p> <p>Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload