PDA

View Full Version : mapView doesn't seem to load map data on device




quinton84
Oct 23, 2009, 12:10 AM
Hi guys,

Iíve 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 Iíve 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 donít 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


#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



KoolStar
Oct 23, 2009, 02:47 PM
After it supposedly zooms in, if you zoom out do you get a map back. If so, you need to fix your zoom as it may be to close to have an image.

quinton84
Oct 26, 2009, 05:29 AM
hi thanks for the help.

I don't think it's a zooming problem. I try to zoom out after it is zoomed in and the map does not load either. I tried 1.0f and 0.15f deltas and both did not work.

MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 1.0f;
region.span.latitudeDelta = 1.0f;
[self.mapView setRegion:region animated:YES];

cwe7976
Dec 28, 2009, 02:03 PM
Hey,

I had the same issue and noticed that it stopped doing it if you explicitly define the mapType.


[aMKMapView setMapType:MKMapTypeStandard];

It is supposed to go to MKMapTypeStandard automatically, but after setting that value my map has seemed to load properly since.

Let me know if this helps!