MKAnnotations 已成功制作,但有时无法在 MKMapView 上呈现

发布于 2024-08-31 12:26:57 字数 925 浏览 5 评论 0原文

我正在使用 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 始终显示有什么想法吗?

I'm working on an iPhone app using the 3.1.3 SDK, my app finds the users current location, displays it on a MKMapView and then finds nearby locations and renders them as MKAnnotations. My code is working, however sometimes the nearby annotations do not appear on the map. They are still being made as I see the correct data in the console (from NSLog which runs just after the annotations are made).

When it fails is completely random, it could be the 5th time I've hit "Build and Run" for the day, or the 500th it doesn't appear to have any pattern and doesn't throw any type of error, it just doesn't add the annotations to the MapView.

This is the method called for each nearby location to add the 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];
}

Any ideas on how to get MKAnnotations to always show?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作死小能手 2024-09-07 12:26:58

我目前正在制作一个想要显示所有可见注释的应用程序 - 我会尝试设置您的地图视图委托,然后实现以下方法:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

在这里您可以找出添加了哪些注释,例如缩放地图以显示它们 - 这博客为您提供了一些源代码来执行此缩放以适应:

http: //codisllc.com/blog/zoom-mkmapview-to-fit-annotations/

以下是一些改进位置信息的好提示:

优化 CLLocationManager/CoreLocation 以在 iPhone 上更快地检索数据点

I'm presently making an app that wants to show all the visible annotations - I would try setting your map view delegate then implementing the following method:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

Here you can figure out what annotations were added and for example zoom the map to show them - this blog gives you some source code to do this zoom-to-fit:

http://codisllc.com/blog/zoom-mkmapview-to-fit-annotations/

Here's some good tips for improving your location information:

Optimizing CLLocationManager/CoreLocation to retrieve data points faster on the iPhone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文