ios - 即使我不动也能获得不同的位置

我正在使用下面的代码来获取longitudelatitude,但是即使我不离开自己的位置,它也会给我带来不同的值

 locationmanager=[[CLLocationManager alloc]init];
    geocoder=[[CLGeocoder alloc]init];

    locationmanager.delegate=self;
    locationmanager.desiredAccuracy=kCLLocationAccuracyBest;
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [locationmanager requestWhenInUseAuthorization];
    }
    [locationmanager startUpdatingLocation];



    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"error" message:@"Failed to get Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }

    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        CLLocation *currentlocation=newLocation;

    if (currentlocation!=nil)
    {

        longitude=currentlocation.coordinate.longitude;
        latitude=currentlocation.coordinate.latitude;

    }
         [geocoder reverseGeocodeLocation:currentlocation completionHandler:^(NSArray *placemarks, NSError *error) {

          } ];

    }


如果我不从自己的家搬来,请指导我,我要在相同的位置。

最佳答案

蜂窝网络位置给出了电话所在区域的大概面积。它基于服务提供商塔楼,因此当前位置将根据网络/ gps位置跟踪/准确性自动更改一点。

我建议您使用距离过滤器来获取位置信息,因此在您位于该区域之前,您的当前地址将与每X米仅更新位置信息一样。

locationManager.distanceFilter = 100;//Your own distance




self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    _locationManager.delegate = self;
    // This is the most important property to set for the manager. It ultimately determines how the manager will
    // attempt to acquire location and thus, the amount of power that will be consumed.
    _locationManager.distanceFilter = 100;
    // Once configured, the location manager must be "started".
    [_locationManager startUpdatingLocation];


希望这可以帮助。