creating setupcontroller in map for iphone - iphone

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?

Related

iOS 6 and Mapkit : User location

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.

Location Manager not working iphone application

[locationManager StarUpdatingLocation]
doesnt work in my case. I have an NSOBject class in which i have a method like this.
(void)findlocation
{
locationManager = [[CLLocationManager alloc] init] ;
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}
Then I have the delegate methods
(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
However using an NSLog statement i figured that the startupdating location method doesnt go into this locationmanager method. :( I am calling the current location method in another method in the same class so i would be saying [self currentLocation]. Any help would be appreciated. thank you.
Conform to protocol CLLocationManagerDelegate in your Class where you have this code.
If this is the case, then you should see whether or not this code is working fine in Device. I think you are running this in simulator & the CLLocationManagerDelegate is not fired & getting upset on code.
If you are using simulator then by default the location of Simulator is set to None.
Kindly check.
Click on Simulator
Check the Debug menu on top of desktop.
Go to Location Submenu
Check for the selected option. If it is none, then choose a custom location. Add values in latitude & longitude. (ex: 13.0524139 , 80.2480755)
If this works then you are good to go in simulator as well.
hope that helps.

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

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.

Can we launch setting screen any no of time in iPhone to enable the GPS?

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];

Is there a callback to use to tell when the user's location is available

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.