问题描述
|
我需要在Map Kit中显示我的当前位置,该怎么做?
self.map.showsUserLocation = TRUE;
没有显示我的位置,而是在地图上的其他位置?我需要找到访问应用程序的位置。
请帮助我。
提前致谢
解决方法
您需要使用位置管理器来获取当前位置。然后获取经纬度值并创建一个注释并显示在地图上。如果使用map.showsUserLocation = TRUE;它将在实际设备中显示您的当前位置。
注意-在模拟器地图工具包中,显示了苹果在库比蒂诺某处的总部位置-我不记得确切了。
,
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@\"%d° %d\' %1.4f\\\"\",degrees,minutes,seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@\"%d° %d\' %1.4f\\\"\",seconds];
longLabel.text = longt;
MKCoordinateRegion region = { {0.0,0.0 },{ 0.0,0.0 } };
region.center.latitude = newLocation.coordinate.latitude;
region.center.longitude = newLocation.coordinate.longitude;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
}