我的视图(MKMapViewDelegate)上有一个mapView插座,启用了"显示用户位置".
在我的控制器的viewdidload中
CLLocation *userLoc = mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
mapView.delegate=self;
Run Code Online (Sandbox Code Playgroud)
模拟器在地图上显示正确的用户位置(我在IOS模拟器中使用自定义位置)
但NSLog显示纬度和经度为0和0.
我不应该在模拟器中获得自定义经度和纬度吗?
更新与答案:
需要实施
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.centerCoordinate = userLocation.location.coordinate;
}
Run Code Online (Sandbox Code Playgroud)
Jim*_*Jim 13
定位服务不是即时的.你的代码在viewDidLoad,所以它还没有机会修复你的位置.您应该将delegate地图视图的属性设置为实现MKMapViewDelegate协议的对象.
| 归档时间: |
|
| 查看次数: |
4584 次 |
| 最近记录: |