I want to know can we turn on/off the GPS programmatically in iPhone?
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.
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];
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.
Related
I was suprise when i saw that my app can't know where I am located with a MapKit on iOS6 !
I just want to zoom to user's location when the map is starting ! How can I do it ?
Please help me
Thank you so much !!
(PS: I saw that the CLCoordinate for sending a request for routing is working fine)
Do you mean that showsUserLocation doesn't have any effect? Or does your location monitoring isn't updating you position? I tested both in iOS 6, works for me. Maybe you could post some code.
EDIT:
Seems like location monitoring is not activated in your app.
First of all you have to do sth like this to enable the cllocation manager:
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
//set the delegate for the location manager
locationManager.delegate = self;
// set your desired accuracy
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
At that point the blue location indicator should be visible. As long as you've set showsUserLocation = YES on your map.
In my app, I dont want to work off of location services. I want to get coordinates using Cell tower triangulation on the iphone.
Please tell me how to do this?
Use API called startMonitoringSignificantLocationChanges. From Apple docs -
startMonitoringSignificantLocationChanges service offers a significant
power savings and provides accuracy that is good enough for most
applications. It uses the device’s cellular radio to determine the
user’s location and report changes in that location, allowing the
system to manage power usage much more aggressively than it could
otherwise.
So in code this is how it would look -
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
I have tried the launch the settings of iPhone in my application using the call
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
[locationManager release];
but I was able to launch only once,now I am not able to launch the settings in my application.
I am using iPhone 3GS with iOS 4.2
Is there any other way to launch settings any no of time if the location services are off.
but I was able to launch only once,now I am not
If you saw an alert kind of msg on your app asking for your permission for using yous gps location. Then this is the default behavior of iPhone OS. if you try to get gps location in any app the OS ask for user's permission. You can not launch this alert again!
but if you wants to change the setting (means wants to enable or disable the location tracking) then you can open the "Settings" application and look for location services setting. You can find your app there and disable the location tracking. But remember you can not open the "Settings" app using your app.
Now this issue is not in iOS5.
If you are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if you tap setting button,it will navigate to phone settings screen. And in phone setting screen you can switch on the location service.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
I am trying to develop the setupcontroller for map it like setting page where user can choose at what time or at rich the some distance user then see his current location automatically.
I try this:
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
but it work one one time. I give user option at time or what distance he need just set and when he rich at that position. Then app show him the current location ON MAPView NOT on UIlable Or in table view. Can anyone help me out?
Are you calling
[locationManager stopUpdatingLocation];
in your delegate?
Is your
didFailWithError:
method called?
I'm after a callback or protocol that will notify me when the user's location is available. So that when a user's location is found I can zoom into where they are. What can I use to do this?
I was thinking there waas something in CoreLocation that could do it, but I can't find how to do it.
[Update]
I've implemented <CLLocationManagerDelegate> with locationManager:didUpdateToLocation:fromLocation: and created an CLLocationManager instance.
locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
but I'm still not getting any location updates. Also if I use didUpdateLocation: then it will re-zoom to the user each update. Is there a better way than having a check to see if it's the first update?
[Update 2]
adding self. to the locationManager got it going and I checked to see if fromLocation: is nil to tell if it was the first update.
Look into the CLLocationManagerDelegate protocol, specifically -locationManager:didUpdateToLocation:fromLocation:. You can get the accuracy of the location reading from the newLocation parameter's horizontalAccuracy property.