当我的 mapView 加载时,我试图在用户当前位置周围设置大约 10 英里的范围。 这是我在 viewDidLoad 中的 Objective C 代码:
self.mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;
[self.view addSubview:self.mapView];
//Set initial scope of map
CLLocationDistance mapWidith = 16000;
CLLocationDistance mapHeight = 16000;
CLLocationCoordinate2D userLocation = self.mapView.userLocation.coordinate;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation, mapHeight , mapWidith);
[self.mapView setRegion: region
animated:false];
当我运行时,它以正确的缩放比例(我认为)开始,但随机集中在大西洋某处。不确定我是否正确访问了 userLocation 坐标,但它似乎是正确的。我对 MKMapView 还很陌生,所以有点挣扎。
最佳答案
mapView 上的 userLocation
属性尚未填充。您应该实现 mapView:didUpdateUserLocation:
方法,之后您可以可靠地使用该属性(或使用发送给您的位置)。
关于ios - MKCoordinateRegionMakeWithDistance 显示错误坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25437146/