我正在使用 3.1.3 SDK 开发 iPhone 应用程序,我的应用程序找到用户当前位置,将其显示在 MKMapView 上,然后找到附近的位置并将它们呈现为 MKAnnotations。我的代码正在运行,但有时附近的注释不会出现在地图上。它们仍在制作中,因为我在控制台中看到了正确的数据(来自 NSLog,它在注释完成后运行)。
当它失败是完全随机的,它可能是我当天第五次点击“构建并运行”,或者第 500 次它似乎没有任何模式并且没有抛出任何类型的错误,它只是不会将注释添加到 MapView。
这是为每个附近位置调用以添加 MKAnnotation 的方法。
- (void)addPinsWithLocation:(NSDictionary *)spot
{
CLLocationCoordinate2D location;
location.longitude = [[spot objectForKey:@"spot_longitude"] doubleValue];
location.latitude = [[spot objectForKey:@"spot_latitude"] doubleValue];
PlaceMarks *placemark = [[PlaceMarks alloc] initWithCoordinate:location title:[spot objectForKey:@"spot_name"] subtitle:@""];
NSLog(@"Adding Pin for Location: '%@' at %f, %f", [spot objectForKey:@"spot_name"], location.latitude, location.longitude);
[mapView addAnnotation:placemark];
}
关于如何让 MKAnnotations 始终显示的任何想法?