Ios 用户当前位置

Ios 用户当前位置,ios,Ios,我想接收用户当前位置的坐标,我输入了以下代码: -(void)update{ locationManager = [[CLLocationManager alloc] init]; locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move locationManager.desiredAccuracy = kCLLocationAccuracyBest; location

我想接收用户当前位置的坐标,我输入了以下代码:

-(void)update{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    mapView.showsUserLocation = YES;
    [locationManager startUpdatingLocation];
}

在iOS模拟器上,这段代码正在崩溃,而在我的设备上它并没有崩溃,或者有时它会崩溃整个应用程序。。。。你能帮我解释一下发生了什么吗?

看起来你可能没有实现这些方法

特别是在以前的iOS版本中,
-locationManager:didUpdateLocations:
(来自iOS 6)或
-locationManager:didUpdateLocation:fromLocation:


也许(同样,你的问题很模糊)你只想在地图视图上显示蓝点。在这种情况下,您不需要与核心位置经理打交道。查看更多信息。

首先,您无法在模拟器中获取当前位置。并尝试使用此代码获取当前位置的坐标

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    if ([CLLocationManager locationServicesEnabled])
    {
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        locationManager.distanceFilter = kCLDistanceFilterNone;
        [locationManager startUpdatingLocation];
    }

    location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];;
    MKCoordinateRegion region;
    region.center=coordinate;
    MKCoordinateSpan span;
    span.latitudeDelta=10.015;
    span.longitudeDelta=10.015;
    region.span=span;
    [mapView setRegion:region];

    NSString *str=[[NSString alloc] initWithFormat:@" latitude:%f longitude:%f",coordinate.latitude,coordinate.longitude];
    NSLog(@"%@",str);

你在模拟器上说“它失败了”是什么意思?你说的“整个应用程序失败”是什么意思?你能描述一下你遇到的碰撞/错误吗?模拟器无法提供整个gps体验。它只具备提供位置的基本能力。这里:请更清楚地说明什么不起作用。你期待什么,什么没有发生?这不是一个Xcode问题…试着用可以理解的语言来回答你的问题…失败这个词意味着崩溃。我需要CLLLocationmanager来实现我设计的独特功能,是的,它是Xcode。谢谢你的帮助,告诉我你的功能在技术上需要实现什么。没有更多的技术信息,任何人都无法帮助您。