iOS:是否可以将注释放在 map 的中心并在注释始终保持在中心的情况下移动 map ?

标签 ios iphone objective-c mkmapview mkannotation

我不知道从哪里开始,但我想知道是否可以这样做。我知道如何将注释放在中心的 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/

相关文章:

ios - 如何限制我的应用程序仅适用于 iPhone

ios - react-native 无法构建 ios : (error xcode Flipper) Typedef redefinition with different types ('uint8_t' (aka 'unsigned char' ) vs 'enum clockid_t' )

iphone - iPhone/Objective-C的try-catch异常处理实践

objective-c - 如何在命令行应用程序中创建安全的密码输入字段?

iphone - 在 UITextView 中创建一个 UIbutton 和 UIImageview

ios - 如何判断苹果应用内购买是后端的调试测试

ios - UICollectionView 和 UITableView 重新加载会导致单元格重新排序

iphone - UIDatePicker 和一个 UITableView

iphone - 如何手动设置 NSManagedObjectID?

ios - 如何立即得到 block 中的结果?