【问题标题】:Zoom to annotations not user location using Mapkit使用 Mapkit 缩放到注释而不是用户位置
【发布时间】:2013-11-21 18:27:24
【问题描述】:

我需要我的应用程序放大地图上填充的注释,而不是用户的位置。这是我会使用的方法吗:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

-(void)viewWillAppear

因此,我还需要地图不仅可以放大注释,还需要确保注释适合地图视图。我查看了一些示例,但似乎找不到适合我的答案。有什么想法吗?

【问题讨论】:

  • 您是否查看过为注释找到边界图矩形并放大到该位置?

标签: ios objective-c mapkit


【解决方案1】:

好的,所以我应该更清楚我的问题,但基本上我想通了。因此,如果您想在地图中添加注释,并在加载它们时缩放到这些注释,那么无论您是从 Web 获取 JSON 数据还是在初始化时定义注释,您都需要执行以下操作:

CLLocationCoordinate2D annotationCoordinate =
                CLLocationCoordinate2DMake([latDest doubleValue],
                                           [lngDest doubleValue]);

                Annotation *annotation = [[Annotation alloc] init];
                annotation.coordinate = annotationCoordinate;
                [self.mapView setCenterCoordinate:annotationCoordinate animated: YES];
                [self.mapView addAnnotation:annotation];

[self.mapView setCenterCoordinate:annotationCoordinate animated: YES];
[self.mapView addAnnotation:annotation];

我创建了一个注释类,其中包含从 JSON 数据收集的每个注释的属性,但最重要且与此问题最相关的是坐标数据,这正是我们所需要的。所以我将我的坐标定义为:

annotationCoordiate

最后在向地图添加注释后,我将地图置于从我的数据中提取的位置的中心:

[self.mapView setCenterCoordinate:annotationCoordinate animated: YES];

希望这是有道理的!谢谢!

【讨论】:

    猜你喜欢
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多