点击后如何在注释上居中或重新定位 Mapbox 地图?
How to center or reposition Mapbox map on annotation after being tapped?
有没有办法在点击 Mapbox 地图后将其置于注释的中心?或者,当标注视图(在本例中为自定义)未完全在视图中时,是否可以在打开注释后重新定位地图?
您可以通过将地图视图的中心坐标设置为 -mapView:didSelectAnnotation:. If you are using annotation views, another option is to set the map view's center coordinate in -mapView:didSelectAnnotationView: 中注释的坐标来使地图视图在注释上居中。
例如:
- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation {
mapView.centerCoordinate = annotation.coordinate;
}
有没有办法在点击 Mapbox 地图后将其置于注释的中心?或者,当标注视图(在本例中为自定义)未完全在视图中时,是否可以在打开注释后重新定位地图?
您可以通过将地图视图的中心坐标设置为 -mapView:didSelectAnnotation:. If you are using annotation views, another option is to set the map view's center coordinate in -mapView:didSelectAnnotationView: 中注释的坐标来使地图视图在注释上居中。
例如:
- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation {
mapView.centerCoordinate = annotation.coordinate;
}