I have a JSON file that contains about 2000 locations that I need to display on the map when the camera is less than 750 meters high. Here is my current code:
func addStops() { var path: String! = NSBundle.mainBundle().pathForResource("stops", ofType: "json") var jsonData: NSData! = NSData(contentsOfFile: path) var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary self.busStops = jsonResult["results"] as NSArray for (var i = 0; i < self.busStops.count; i++) { let lat = self.busStops[i]["latitude"] as NSString let lng = self.busStops[i]["longitude"] as NSString var annotation = busAnno() annotation.setCoordinate(CLLocationCoordinate2DMake(CLLocationDegrees(lat.doubleValue), CLLocationDegrees(lng.doubleValue))) annotation.type = "stop" self.mapView.addAnnotation(annotation) } }
And the annotation view delegate:
func mapView (mapView: MKMapView!, viewForAnnotation annotation: MKPointAnnotation!) -> busMarker! { var pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: "point") pinView.location = annotation.location pinView.hidden = true pinView.layer.hidden = true pinView.enabled = false }
It seemed to me that I can leave just by hiding my eyes, but 20 seconds before the application even responds by adding markers, it takes 20 seconds, and then it is impossible to smoothly move the card (drops to 5 frames per second).
So, if I canβt do this, then which approach is better? I assume that checking for a pair of coordinates within the boundaries of the screen every time the map move will not work properly due to a delay (based on checking 2000 coordinates each time). Any ideas?
EDIT
You will only see 10 annotations of the year 2000, as you have to be very enlarged to see them. This is just the case when I use the quick search method for annotations in this region without this terrifying delay.
source share