2

我正在开发一个基于位置的应用程序,我正在使用以下代码(完美运行)来检索用户的位置。但是,我想为经度和纬度设置一个默认值,以防用户关闭位置服务。

我试过 self.latitude = 0; 但应用程序崩溃。纬度和经度是浮点类型的变量。理想情况下,我想将它们设置为默认值(0,0)。

所以基本上:如何为类型变量设置默认值float

谢谢你的帮助。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation    *)newLocation fromLocation:(CLLocation *)oldLocation
{
    self.latitude = newLocation.coordinate.latitude;
    self.longitude = newLocation.coordinate.longitude;
    SVGeocoder *geocodeRequest = [[SVGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    [geocodeRequest setDelegate:self];
    [geocodeRequest startAsynchronous];
    //   NSLog(@"lat:%f,long:%f",self.latitude,self.longitude);

    [self.locationMgr stopUpdatingLocation];
}
4

0 回答 0