Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we turn on/off the GPS programmatically in iPhone?

I want to know can we turn on/off the GPS programmatically in iPhone?

like image 253
User97693321 Avatar asked Aug 09 '11 06:08

User97693321


3 Answers

A simple example:

//Init location manager 

CLLocationManager* locationManager = [ [ CLLocationManager alloc] init];
locationManager.delegate = self; //we must implement the protocol

//Choose your accuracy level

//To turn on gps (if it isn't on already)
[locationManager startUpdatingLocation];

//To turn gps off (if no other apps are listening)
[locationManager stopUpdatingLocation];

There is more than this, and you can monitor more or less accuracy, and even use wifi/ cell towers. Please read the example first for best usage.

like image 105
Mitchell Currie Avatar answered Oct 12 '22 11:10

Mitchell Currie


Previous to iOS 5 the behavior was not consistent for launch of phone setting from third party application, but in iOS5 this is improved.

If we are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if we tap setting button,it will navigate to phone setting.

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
like image 38
User97693321 Avatar answered Oct 12 '22 09:10

User97693321


Well the GPS will be turned on if you use the CLLocationManager.

The locationmanager will first start by getting the location via triangulation and then turn the GPS to get a more precise fix.

like image 5
rckoenes Avatar answered Oct 12 '22 09:10

rckoenes