如何在MKMapView中居我当前的位置? [英] How to center my current location in MKMapView?
问题描述
我使用 showUserLocation $ c在
MKMapView
中显示当前位置
$ c>启用。我还想将 mapview
集中到用户当前位置以及缩放的位置图。请帮我解决这个问题,因为我在stackoverflow上没有得到任何其他类似问题的帮助。
I am showing the current location
in MKMapView
by using showUserLocation
enables. I also want to center the mapview
to the user current location and also the zoomed map of location. Please help me regarding this as I don't get any help from other similar questions on stackoverflow.
我的代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
[mapView setDelegate:self];
}
推荐答案
以中心用户位置为准您可以使用以下代码:
For centering on user location, you can use the following code:
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
要放大特殊地点,你应该研究一下这些地区( MKCoordinateRegion
)计算并运行,计算您所在地区的值并使用调用显示它:
For zooming on special locations, you should study how the regions (MKCoordinateRegion
) are counted and work, count your values for the region and display it using call:
[mapView setRegion:myRegion animated:YES];
这示例WorldCities 显示区域显示的基础知识。
This sample WorldCities shows basics of region displaying.
这篇关于如何在MKMapView中居我当前的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!