简体   繁体   English

MKMapView在地图上加载成千上万的针脚

[英]MKMapView Loading Thousands of Pins on the Map

I need to displays thousands of pins on the MKMapView and I need a good delegate method where I can add the pins. 我需要在MKMapView上显示数千个引脚,我需要一个好的委托方法,我可以添加引脚。 didUserUpdateLocation is bad because it is fired multiple times. didUserUpdateLocation很糟糕,因为它被多次触发。 What is the best way to add thousands of pins to the MKMapView. 向MKMapView添加数千个引脚的最佳方法是什么?

UPDATE: 更新:

I just used a BOOL check to load the pins one time only and it seemed to work really good! 我只是使用BOOL检查一次加载引脚,它似乎工作得非常好!

-(void) mapView:(MKMapView *) mv didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"didUpdateUserLocation");

    if(self.isMapped) return; 

    for(Facility *facility in self.facilities) 
    {
        CLLocationCoordinate2D facilityCoord = { facility.latitude,facility.longitude };


        MapPoint *mp = [[MapPoint alloc] initWithCoordinate:facilityCoord title:facility.facilityName];



        [mv addAnnotation:mp];

    }

    self.isMapped = YES; 

}

I use mapView:regionDidChangeAnimated:. 我使用mapView:regionDidChangeAnimated:。 I pull data from Core Data filtering by latitude and longitude to get pins for the current region and surroundings so the user can scroll a bit without pulling data again. 我通过纬度和经度从核心数据过滤中提取数据,以获取当前区域和周围环境的引脚,以便用户可以滚动一点而不会再次提取数据。

When zooming out you can decide to show a clustered version of your data that you can precalculate or calculate at runtime using the K-Means algorithm. 缩小时,您可以决定显示数据的聚类版本,您可以使用K-Means算法在运行时预先计算或计算。

It may help if you have a high amount of data to use a light data structure based on structs instead objects. 如果您有大量数据来使用基于结构而不是对象的轻型数据结构,这可能会有所帮助。

When adding and removing pins you may want to animate a fade-in/fade-out to smooth the transitions. 添加和删​​除引脚时,您可能需要为淡入/淡出设置动画以平滑过渡。 It's a bad user experience to be popping in and out stuff on screen. 在屏幕上弹出一些东西是一种糟糕的用户体验。

If server calls are involved in all this, you can encapsulate the calls in NSOperations so you can cancell old calls when the user moves too fast through the map. 如果所有这些都涉及服务器调用,则可以将调用封装在NSOperations中,以便在用户在地图中移动太快时取消旧调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM