location problem in IOS4 - iphone

i am using location in my app and tested it with IOS 3 simulatior it works fine also on device it works fie.
but when tested it on IOS4 simulator it crashes..and unable to find location
I know that the location on simulator is of infinite loop cupertino california.
but it is not working in IOS4...
and i don't have Iphone4...So can't test further
please help

Maybe the simulator can't retrieve the default CLLocationManager location.
You can try this:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
location = newLocation.coordinate;
// Manually setting a default location for simulator only
if(TARGET_IPHONE_SIMULATOR){
location.latitude= 45.00;
location.longitude= 45.00;
}
}

Related

didUpdateLocations delegate method not call in iOS 5.1 and earlier

I am using CoreLocation Framework for getting latitude and longitude in my project.
I have implement this delegate method in my .m file
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(#"Locations : %#", locations);
}
But in iOS 5.0 & 5.1, this method is not call.
and in iOS 6.0 or later it's call properly.
so how to call this method in iOS 5.0 or later.
didUpdateLocations: did not exist in ios 5 or earlier. If you want to support those ios version then just use the deprecated didUpdateToLocation:fromLocation. Even though it is deprecated it still works in ios 6 and 7. That's the simplest solution.
You could have delegate methods for both, but that gets more complicated to manage. If you don't need to build track logs in the background then you don't really need didUpdateLocations: it was created to save battery power while collecting multiple points when running in the background.
See this answer...This method for iOS 5 (deprecated on iOS 6)and old version.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
This method for iOS 6 and later version..
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
Refer:
http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html
As you can see locationManager:didUpdateLocations: is available only in iOS 6.0 and later.
You can always get the recent updated location from
CLLocationManger's location
property.

How can CLLocationManager call correct delegate methods depending on iOS version

In iOS 5 , delegate method is
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
where as in iOS 6 method is
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
My app supports both version. How CLLocation manage will know which method it should call ?
Do I need to add some #if def ? If yes , can anybody tell me how can I write this.
Thanks in advance.
You can use
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
You can build using iOS 6 SDK and set the deployment target to support iOS 5 as well. In case if it doesn't work, you can try implementing this method and call - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
inside that(You can implement this iOS 6 method as well, so that in case of iOS 6 it calls this method directly). You can create an array out of newLocation and oldLocation and pass to this. But I dont think that will be needed. You can test it out in both devices.

iPhone: Catch the events when App running in background

Can anyone please let me know if it is possible to handle events like OrientationChanged, Shake, LocationChanged etc.. when my App running in background?
I have tried following code but it gets invoked only when my app running in foreground!
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//if the time interval returned from core location is more than two minutes we ignore it because it might be from an old session
if ( abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 120) {
self.currentLocation = newLocation;
}
NSLog(#"lat: %f long:%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
}
Thanks.
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
You should include location-services in your info.plist file under the key UIRequiredDeviceCapabilities
then your app will receive location updates in the background.
However this drains the battery at a faster rate..without user knowing much..If possible you should register for only significant location
orientation changed updates won't be possible in background.
shake might be..i am not sure

MKMapview showing current location wrong

I am using MKMapView and it is showing my current location. in india it is showing well and exact what in google map but in US current location is showing wrong.
i am using
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
any help please ?
If you are using an MKMapView you can use its delegate method mapView:didUpdateUserLocation:
You need to set showsUserLocation property of your map view to YES.
Then the map view uses CoreLocation framework to determine current location.
It tracks userLocation by itself whenever it receives location updates and updates it periodically.

How to keep get location info and add to mapview when iphone in screensaving mode

I am using
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
to keep receiving location information, then add annotation to MKMapView. It appears that it stop updating when iPhone screen in screen saving mode.
Could you turn off the screensaving mode? You can do so by calling: [UIApplication sharedApplication].idleTimerDisabled = YES; This should solve your problem.