#define LOCATION_DISTANCE 80.4672
- (void)viewDidLoad
{
[super viewDidLoad];
....some computation
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 360.0*NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[locationManager stopUpdatingLocation];
});
..........some more computation
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *obj = [locations lastObject];
if (obj.coordinate.latitude != 0 && obj.coordinate.longitude != 0 )
{
CLLocationCoordinate2D currrentCoordinates ;
currrentCoordinates.latitude = obj.coordinate.latitude;
currrentCoordinates.longitude = obj.coordinate.longitude;
if(obj.horizontalAccuracy>0 && obj.horizontalAccuracy<100){
self.turnedOffLocationServices =YES;
[locationManager stopUpdatingLocation];
} .... more computation
[self setUpMap:currrentCoordinates];
}
- (void)setUpMap:(CLLocationCoordinate2D)currentCoordinates
{
MKCoordinateRegion extentsRegion = MKCoordinateRegionMakeWithDistance(currentCoordinates, LOCATION_DISTANCE, LOCATION_DISTANCE);
MKMapView *mvMap = [[MKMapView alloc] initWithFrame:CGRectMake(20, 594, 360, 347)];
mvMap.delegate = self;
[mvMap setRegion:extentsRegion animated:YES];
mvMap.mapType = MKMapTypeSatellite;
mvMap.autoresizingMask = UIViewAutoresizingNone;
//mvMap.showsUserLocation = YES;
NSLog(@"the current lat is %f", currentCoordinates.latitude);
NSLog(@"the current long val is %f", currentCoordinates.longitude);
[self.scrollView addSubview:mvMap];
ITMAnnotation *annotation = [[ITMAnnotation alloc] initWithCoordinate:currentCoordinates addressDictionary:nil];
annotation.title = @"Drag to Move Pin";
annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
NSLog(@"subtitle change at 314");
[mvMap addAnnotation:annotation];
self.tempMapView = mvMap;
}
So i have viewDidLoad that creates location manager. I use didUpdateLocations as I think it is supposed to. I call setUpMap method with that co-ordinates and i get a map at the bottom left corner of my ipad screen.
My problems are:1)When in no-wifi/cell mode i don’t get the accurate location. Its way off. But i put in the co-ordinates manually( have text fields which will take this co-ordinates) it works and shows the location.
2)I added suppose 4 records in this no-wifi/no cell mode. I can add 3 fine with map showing( but again different location way off my current location). But on the 4th time(or later some time) when i visit the screen where map should show up is white. Does this make sense. IF you need more information please ask. Thanks.. Oh and all this is on the device NOT simulator. And its iOS6.
The cell and the GPS are on the same chip so turning the cell off turns off the GPS too. If you just want to stop data transfers but still want GPS then you can turn off Mobile Data under Network settings. You’ll still be able to make calls, but your device can’t download anything (if you turn off wifi too).