Hi guys,
Ive been working on mapkit to start and zoom into my current location's region[some code based on the pragmatic bookshelf's iphone programming book]and Ive encountered a rather bizzare problem.
Whenever I start the app on my iphone device,
1. it will load the world map,
2. then the blue dot will drop in
3. and the screen will attempt zoom in to where I am (Singapore).
4. But the map data does not load. I just get a grey grid screen with the blue location dot in the centre.
No amount of waiting seems to load the map.
mapViewWillStartLoadingMap is called. but mapViewDidFinishLoadingMap is not called. neither is mapViewDidFailLoadingMap.
To further compound this bizzare problem, I dont get that problem when I run it on the emulator.
However, it is to be noted that America is part of the world map loaded, while Singapore lies outside the boundaries of the world map that loads at the start.
Is this a bug? I've been working on it for a long time now but still remain clueless. did I miss out on something? Thanks!
Nelson
Ive been working on mapkit to start and zoom into my current location's region[some code based on the pragmatic bookshelf's iphone programming book]and Ive encountered a rather bizzare problem.
Whenever I start the app on my iphone device,
1. it will load the world map,
2. then the blue dot will drop in
3. and the screen will attempt zoom in to where I am (Singapore).
4. But the map data does not load. I just get a grey grid screen with the blue location dot in the centre.
No amount of waiting seems to load the map.
mapViewWillStartLoadingMap is called. but mapViewDidFinishLoadingMap is not called. neither is mapViewDidFailLoadingMap.
To further compound this bizzare problem, I dont get that problem when I run it on the emulator.
However, it is to be noted that America is part of the world map loaded, while Singapore lies outside the boundaries of the world map that loads at the start.
Is this a bug? I've been working on it for a long time now but still remain clueless. did I miss out on something? Thanks!
Nelson
Code:
#import "MapViewController.h"
@implementation MapViewController
@synthesize mapView;
@synthesize segCtrl_MapType;
/*********************************************
IB ACTIONS
*********************************************/
- (IBAction) mapType:(UISegmentedControl *)segmentPick {
switch (segmentPick.selectedSegmentIndex) {
case 0:
mapView.mapType = MKMapTypeStandard;
break;
case 1:
mapView.mapType = MKMapTypeSatellite;
break;
case 2:
mapView.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
/**END IB ACTIONS******************/
//SetCurrentLocation
//Zooms in the mapView on the user's current location
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.mapView setRegion:region animated:YES];
//[mapView setRegion:MKCoordinateRegionMake([location coordinate], MKCoordinateSpanMake(.015f, .015f)) animated:YES];
}
//END SetCurrentLocation
/*********************************************
MKMapView DELEGATES
*********************************************/
//DELEGATE viewForAnnotation
//Called whenever an annotation is being dropped on the map
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
//NSLog(@"viewForAnnotation called");
// the annotation being dropped is for the user's current locations
if ([annotation isKindOfClass:[MKUserLocation class]])
{
//NSLog(@"User Location");
NSLog(@"Zooming in on user location");
BOOL userLocationVisible = mapView.userLocationVisible;
NSLog(@"userLocationVisible: %@\n", (userLocationVisible ? @"YES" : @"NO"));
NSLog(@"showUserLocation: %@\n", (mapView.showsUserLocation ? @"YES" : @"NO"));
CLLocation *location = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude
longitude: annotation.coordinate.longitude];
[self setCurrentLocation:location];
}
else { //this is for any other annotation e.g.
NSLog(@"Other Annotations");
return nil; //TODO: change to annotate IMAGES.
}
return nil;
}
//END viewForAnnotation
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
NSLog(@"region did change");
//TODO: Add photos around the region
[fapi_request callAPIMethodWithGET:@"flickr.photos.search" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"1", @"has_geo",@"geo,tags",@"extras",nil]];
}
- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView {
NSLog(@"map view will start to load map");
}
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
NSLog(@"map view finished loading map");
}
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error {
NSLog(@"map view failed to load map: %@",error.localizedDescription);
}
/**END MKMapView DELEGATES******************/
/*********************************************
UIViewController
*********************************************/
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//setup mapView
mapView.delegate = self;
mapView.showsUserLocation = YES;
//setup locationmanager
/*
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
*/
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
/**END UIViewController******************/
- (void)dealloc {
[mapView release];
[segCtrl_MapType release];
[super dealloc];
}
@end