userLocation始终为0.0000,0,0000

时间:2012-05-25 20:00:27

标签: objective-c xcode

我试图在MKMapKit中返回用户位置,但是在LOG中,它总是返回0.0000,0.0000。当项目运行时,它会在地图上显示userLocation ..但是在log show 0,0 ..

有些人知道怎么做吗?看看我的代码:

- (void)viewDidLoad

{     [super viewDidLoad];

//esconder navBar
[[self navigationController] setNavigationBarHidden:YES animated:NO];

mapView.showsUserLocation = YES;


double lat = -21.21258;
double lng = -47.816802;

CLLocationCoordinate2D Coordinate;

NSLog(@"%f , %f", mapView.userLocation.coordinate.longitude, mapView.userLocation.coordinate.latitude);

Coordinate.latitude = lat;
Coordinate.longitude = lng;

MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = Coordinate;
annotationPoint.title = @"Ribeirão Shopping";
annotationPoint.subtitle = @"Ribeirão Preto - SP";
[self.mapView addAnnotation:annotationPoint]; 

MKCoordinateRegion newRegion;
newRegion.center.latitude = lat;
newRegion.center.longitude = lng;
[self.mapView setRegion:newRegion animated:YES];

mapView.mapType = MKMapTypeStandard;

}

谢谢!

1 个答案:

答案 0 :(得分:1)

查找mapview的用户位置确实需要一些时间,所以在使用mapView.userlocaiton git几秒~3之前给它一些时间,然后尝试记录用户位置。我相信你会在那里得到它。