在MKMapView中加载可见区域的注释 [英] Load annotations for visible region in MKMapView

查看:89
本文介绍了在MKMapView中加载可见区域的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约400个MKAnnotationView,它们同时加载到MKMapView中.

I have about 400 MKAnnotationView´s that loads simultaneously into the MKMapView.

我知道这没什么用,它有点慢,我想以正确"的方式来做.

I understand that this isn't any good, it is a little bit slow, and I want to do it the "correct" way.

我通过中心坐标缩放地图:

I zoom my map by a center coordinate:

MKCoordinateSpan span;
span.latitudeDelta = 0.8;
span.longitudeDelta = 0.8;

MKCoordinateRegion region;
region.span = span;

region.center = self.selectedCounty.coordinate;

[mapView setRegion:region animated:TRUE]; 

我只想加载在该区域可见的注释.

I only want to load the annotations that could be visible in that region.

我有一个自定义的MKAnnotation,简称为"Annotation",具有CLLocationCoordinate2D-和title-property.

I have a custom MKAnnotation called simply "Annotation" with a CLLocationCoordinate2D- and title-property.

我只是想在MKMapView上加载可见区域"的注释,因此并非所有注释都同时加载.而且,当MKMapView上的可见区域"发生变化时,我当然希望为该区域加载注释.

I simply want to load the annotation for the "visible area" on the MKMapView so not all the annotation loads at the same time. And when the "visible area" on the MKMapView changes, I of course want to load annotations for that area.

我知道MKMapView有一个委托方法,该方法在区域更改时运行.

I know that MKMapView has a delegate method which runs when the region changes.

但是我怎么知道应该为该区域加载哪些注释?

But how do I know what annotations I should load for that region?

推荐答案

您可以获取地图区域的跨度和中心,并根据注释的位置,可以检查该区域内是否有任何注释...也许已经在[mapview isAnnotationVisible]之类的方法中实现了...但是您最终必须检查每个注释...

You can get the map region span and center, and based on the locations of the annotations you could check if any annotation is inside that region... maybe it is implemented already in something like [mapview isAnnotationVisible]... but you'll have to check everyone of the annotations eventually...

这篇关于在MKMapView中加载可见区域的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆