简体   繁体   English

点击后如何在注释上居中或重新定位Mapbox地图?

[英]How to center or reposition Mapbox map on annotation after being tapped?

Is there a way to center a Mapbox map onto an annotation after it's been tapped? 点击后,是否可以将Mapbox地图置于注释的中心? Or is there a way to reposition the map after an annotation has been opened when the callout view (custom, in this case) is not entirely in view? 还是在标注视图(在这种情况下为自定义)未完全出现在注释中的情况下,有一种方法可以在打开注释后重新定位地图?

You can center a map view on an annotation by setting the map view's center coordinate to the coordinate of the annotation in -mapView:didSelectAnnotation: . 通过将地图视图的中心坐标设置为-mapView:didSelectAnnotation:中的注释坐标,可以将地图视图以注释为中心。 If you are using annotation views, another option is to set the map view's center coordinate in -mapView:didSelectAnnotationView: . 如果使用注释视图,则另一个选项是在-mapView:didSelectAnnotationView:中设置地图视图的中心坐标。

For example: - (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation { mapView.centerCoordinate = annotation.coordinate; } 例如- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation { mapView.centerCoordinate = annotation.coordinate; } - (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation { mapView.centerCoordinate = annotation.coordinate; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM