我不知道从哪里开始,但我想知道是否可以这样做。我知道如何将注释放在中心的 mapview 中。这就是我到目前为止所拥有的。如果有人知道如何在我更改区域时将注释调整到 map 中心,我将不胜感激。
- (IBAction)recenter:(id)sender {
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = mapView.centerCoordinate;
pa.title = @"Map Center";
pa.subtitle = [NSString stringWithFormat:@"%f, %f", pa.coordinate.latitude, pa.coordinate.longitude];
[mapView addAnnotation:pa];
self.centerAnnotation = pa;
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
centerAnnotation.coordinate = self.mapView.centerCoordinate;
centerAnnotation.subtitle = [NSString stringWithFormat:@"%f, %f", centerAnnotation.coordinate.latitude, centerAnnotation.coordinate.longitude];
}
最佳答案
不使用注释,而是向保存 map 的 View 添加 subview ,并将两个 View 的 center
设置为彼此相等。当用户平移 map 时,注释看起来就像在移动。
然后每当您需要找到中心“注释”指向的坐标时,您可以使用 map View 的 centerCoordinate
属性。
我已经在 map 框和谷歌地图中完成了此操作,但在 MapKit 中没有这样做,但我认为它应该可以正常工作。
关于iOS:是否可以将注释放在 map 的中心并在注释始终保持在中心的情况下移动 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246771/