xcode 如何设置我的地图视图以自动放大用户的当前位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14313063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set my mapview to automatically zoom in on user's current location?
提问by user1953744
When I click on the "Map" button in my tab bar, it pulls up my Map View Controller, and shows the user's current location on the mapview (I'm using the following code):
当我点击标签栏中的“地图”按钮时,它会拉出我的地图视图控制器,并在地图视图上显示用户的当前位置(我正在使用以下代码):
[mapview setShowsUserLocation:YES];
Super easy. But if I want the map to automatically zoom in on the user's current location, how do I go about doing this (in xCode)?
超级容易。但是,如果我希望地图自动放大用户的当前位置,我该怎么做(在 xCode 中)?
Thanks :)
谢谢 :)
回答by Carlos Vela
i think this is what you need
我想这就是你需要的
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.showsUserLocation=YES;
self.mapView.delegate = self;
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
//some code
}
回答by Craig
[mapview setUserTrackingMode:MKUserTrackingModeFollow];
[mapview setUserTrackingMode:MKUserTrackingModeFollow];
回答by Nitin Alabur
this should do what you are looking for
这应该做你正在寻找的
MKCoordinateRegion region;
region = (MKCoordinateRegion){(current user location).location.coordinate, (current user location).locationCoordinateSpan};
[theMapView setRegion:region animated:NO/YES];