简体   繁体   中英

iOS: Is it possible to ask core location framework to fetch location using only cell tower or only WiFi or using GPS antennas?

I am trying to fetch location data in an iOS application using Core Location framework. I am using below code snippet to initiate the location manager.

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 5;

I understand that I can change the accuracy of the location data using desiredAccuracy parameter. But how does actually core location work? Does it fetch using GPS antennas or WiFi or cell towers? Can I ask the location manager to fetch only using GPS or only WiFi or only Cell tower?

As rmaddy mentioned, you do not have control over how the location is determined. In other words, you cannot ask the app/device to use one of GPS/CellTower/Wifi.

However you can, through the type of location update, tell the App whether to "favor" GPS or Cell Tower.

If you do:

[locationManager startUpdatingLocation];

Then the app will definitely use GPS + maybe wifi and/or cell tower.

if you do:

[locationManager startMonitoringSignificantLocationChanges];

Then the app will definitely use cell tower and provide a location update when you move from one cell tower to the next. This should reduce your GPS usage and battery usage. Having said that, I am not sure if in this case, GPS usage is completely eliminated.

Hope this sheds some light.

Update

See Apple's link: CLLocationManager Class Reference

But in general you can always get one update (will arrive through the delegate method) and then use:

[locationManager stopMonitoringSignificantLocationChanges];

You will have to do a bit more work and check the timestamp of the location to make sure the update is not one of the old cached one.

You can't force CL to use GPS or Wifi or cell but you can set desiredAccuracy so that it will probably do what you want.

If you set desiredAccuracy to 500 or higher it will use Wifi or Cellular if available, and leave the GPS off. If you set desiredAccuracy to 300 or less it will have to use GPS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM