MKCoordinateRegionMakeWithDistance显示错误的坐标

时间:2014-08-21 22:48:18

标签: ios mkmapview cllocationcoordinate2d

当我的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的新手,所以我有点挣扎。

1 个答案:

答案 0 :(得分:1)

尚未填充mapView上的userLocation属性。您应该实现mapView:didUpdateUserLocation:方法,之后您可以可靠地使用该属性(或使用发送给您的位置)。