Ios5 用户位置未显示在地图中
我需要在地图上用蓝色圆点显示用户当前位置。我用了CLLocationManager。但仅显示mapview。我寄了定制的lat,long。但这个lat,long不能显示在地图上 代码:Ios5 用户位置未显示在地图中,ios5,mkmapview,mapkit,cllocationmanager,Ios5,Mkmapview,Mapkit,Cllocationmanager,我需要在地图上用蓝色圆点显示用户当前位置。我用了CLLocationManager。但仅显示mapview。我寄了定制的lat,long。但这个lat,long不能显示在地图上 代码: 使用InterfaceBuilder,将地图视图放到屏幕上,勾选“显示用户位置”旁边的框 此外,您不需要locationmanager来显示用户位置,mapview将负责这一点 - (void)viewDidLoad { UIView *vc=[[UIView alloc]initWithFrame:CG
使用InterfaceBuilder,将地图视图放到屏幕上,勾选“显示用户位置”旁边的框 此外,您不需要locationmanager来显示用户位置,mapview将负责这一点
- (void)viewDidLoad
{
UIView *vc=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:vc];
MKMapView *map = [[MKMapView alloc] init];
map.frame = CGRectMake(0, 0, 320, 480);
map.showsUserLocation=YES;
[self.view addSubview:map];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
// NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
CLLocationCoordinate2D loc = [newLocation coordinate];
NSLog(@"current longitude = %f , current latitude = %f",loc.longitude,loc.latitude);
}