如何将用户跟踪按钮添加到MKMapView?

问题描述 投票:1回答:2

我想在MKMapView上添加一个按钮,将地图移动到当前用户位置。我在很多应用程序上看到了这个图标:

这有什么课吗?或者我应该自己创建它?我知道我可以使用MKUserTrackingBarButtonItem,但我不想使用导航栏。

objective-c swift mkmapview
2个回答
0
投票

你试过 - myMapView.showsUserLocation = YES?


0
投票

根据需要添加按钮/图像,当您想要移动到用户的位置时,请调用以下方法:

- (void)zoomToUserLocation {
    // create a region object with the user's location as the center coordinate, and some
    // arbitrary value you'd like as the region span (.005 is one I use regularly)
    MKCoordinateRegion region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, MKCoordinateSpanMake(0.005, 0.005));
    [_mapView setRegion:region animated:TRUE];
}
© www.soinside.com 2019 - 2024. All rights reserved.