开发者

iOS how to keep current location center all the time

开发者 https://www.devze.com 2023-04-05 21:12 出处:网络
My map shows current location with blue dot.. Of course, when I move, blue dot moves.. I just wan开发者_如何学编程t to keep blue dot center of the map all the time, making map\'s moving instead like G

My map shows current location with blue dot.. Of course, when I move, blue dot moves.. I just wan开发者_如何学编程t to keep blue dot center of the map all the time, making map's moving instead like Google map navigator..

I searched a lot but couldn't find the way...


In your map view delegate, do this:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    [mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}


Try using mapView.userTrackingMode = MKUserTrackingModeFollow;, you'll get smoother panning than using the location manager manually.

In addition note that there is a ready-made button for managing the various tracking states: MKUserTrackingBarButtonItem.


The easiest way would be to create a new UIView on top of your map's view with a blue dot and only move the map's view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号