Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios5 用户位置未显示在地图中_Ios5_Mkmapview_Mapkit_Cllocationmanager - Fatal编程技术网

Ios5 用户位置未显示在地图中

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

我需要在地图上用蓝色圆点显示用户当前位置。我用了CLLocationManager。但仅显示mapview。我寄了定制的lat,long。但这个lat,long不能显示在地图上

代码:


使用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);
}