我试图从我的代码中每 10 秒更新一次用户位置。但是当我从 wifi 转移到 3G 时,我遇到了一个问题。每个备用请求都来自我的 wifi 所在的位置。可以做什么?
这是我的代码
NSNumber *n1; NSNumber *n2;
if([ud boolForKey:@"applicationActive"])
{
n1 = [NSNumber numberWithDouble:[map.userLocation coordinate].latitude];
n2 = [NSNumber numberWithDouble:[map.userLocation coordinate].longitude];
}
else
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
n1 = [NSNumber numberWithDouble:locationManager.location.coordinate.latitude];
n2 = [NSNumber numberWithDouble:locationManager.location.coordinate.longitude];
[locationManager stopUpdatingLocation];
}
[dict setObject:[ud objectForKey:@"CurrentDriverID"] forKey:@"DriverId"];
[dict setObject:[n1 stringValue] forKey:@"Latitude"];
[dict setObject:[n2 stringValue] forKey:@"Longitude"];
[requestG SaveDriverlocationWS:dict delegate:self];
注意:发生这种情况时,应用程序将停留在前台。SaveDriverlocationWS 方法将当前位置保存到服务器