开发者

iOS how to keep current location center all the time

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜