MapKit寻找比我指定的更多注释

时间:2013-06-04 19:24:41

标签: ios mapkit mkannotationview

我有一个应用调用addAnnotation正好3次(在使用CLLocationCoordinate2DIsValid验证坐标正常后,传递响应id的模型,title { {1}},latitudelongitude。在模型中,我通过coordinate方法中的NSLog观看回调。

请注意,coordinatecoordinate是作为方法实现的,虽然这应该没有区别,对吧?

我的期望:

MapKit将访问坐标方法3次

我得到了什么:

MapKit每个坐标访问坐标3次,然后尝试第4次,即使没有第4个坐标且应用程序在内存异常时崩溃,结果为name

我对MapKit非常天真,但是我必须要解释这个问题。

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

如果用户位置显示在地图上(蓝点),您将有四个注释,因为蓝点也是注释。

您的应用可能会崩溃,因为用于显示用户位置的注释没有名为coordinate的方法

为防止代码调用方法coordinate,您可以检查检索到的注释是否是自定义注释类的实例:

if ([annotion isKindOfClass:[YourCustomeAnnotation class]])
    // it's one of your annotations
else
    // it's the current location annotation 

或检查当前注释是否为当前位置anotation

if ([annotion isKindOfClass:[MKUserLocation class]])
    // it's the current location annotation 
else
    // it's one of your annotations