Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

CLLocationManager doesn't detect latitude and longitude

Hi ,

i am facing one problem while using CLLocationManager class to get latitude and longitude. It works fine when device has network(wifi or cellular network). But in some devices when there is no network it fails and "didFailWithError" delegate gets called. Here is the observation :


iPhone 4 : Works fine with or without network(wifi or cellular network)

iPhone 3gs : Works only when there is network(wifi or cellular network)


I came to know that iPhone uses AGPS, does it mean that it always require network . If so how it worked in iPhone 4. Please suggest me what is going wrong here ?

CLLocationManager,AGPS, GPS

Posted on Aug 14, 2012 2:32 AM

Reply
11 replies

Aug 15, 2012 7:34 AM in response to Kumar007

kCLErrorLocationUnknown = 0, // location is currently unknown, but CL will keep trying

Have you tried giving it more time? AGPS uses the gross position from the cell or WiFi to give the GPS chip a starting point allowing it to get an accurate position quicker. You take this advantage away with the network turned off. I'll wager you have locationManager.desiredAccuracy set high.

Aug 16, 2012 10:22 AM in response to xnav

I tried many times in different scenarios(with no network) but 3GS only first time it gave the location then failed but in iPhone 4 after "Failed" delegate call also it was giving location values continuously.



Here is the sample code :


CLLocationManager *locationManager = [[CLLocationManageralloc] init];

[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];

locationManager.distanceFilter = kCLDistanceFilterNone;

[locationManager setDelegate:self];

[locationManager startUpdatingLocation];

Aug 23, 2012 2:27 AM in response to xnav

I tried with another 3GS device but same problem exist, its not detecting location. Checked with another application as well.


Actually my intension was to use AGPS for some time(if there is network) and after some threshhold time period use only GPS. But i didn't find any Api to achieve this task. Basically switch between AGPS and GPS programmatically. Is this possible ?


Thanks

Aug 23, 2012 7:55 AM in response to Kumar007

From the Location Awareness Programming Guide:


Gathering location data is a power-intensive operation. It involves powering up the onboard radios and querying the available cell towers, Wi-Fi hotspots, or GPS satellites, which can take several seconds. Leaving the standard location service running for extended periods can drain the device’s battery. (The significant-change location service drastically reduces battery drain by monitoring only cell tower changes, but the service works only on devices with cellular radios.) For most applications, it is usually sufficient to establish an initial position fix and then acquire updates only periodically after that. If you are sure you need regular position updates, you should use the significant-change location service where you can; otherwise, you should configure the parameters of the standard location service in a way that minimizes its impact on battery life.


Again, how are you 'turning off' the cellular net when testing?

CLLocationManager doesn't detect latitude and longitude

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.