i am using xcode 4.3.3.
I am trying a sample mapview app. In which i just have 1 view controller with 1 mapview. I want to show a particular location whose coordiates i have set in my code. When i run without setting a region my map shows default America region, but when i set my region with coordinates it shows only grey tiles and nothing. Below is my code.
#import "BranchViewController.h"
#import <MapKit/MapKit.h>
#import "Annotation.h"
@interface BranchViewController ()
@end
#define CBB_LATITUDE 26.2167;
#define CBB_LONGITUDE 50.5833;
#define THE_SPAN 0.01f;
@implementation BranchViewController
@synthesize myMapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSLog(@"BranchViewController - viewDidLoad()");
[super viewDidLoad];
// Do any additional setup after loading the view.
// CBB REGION
MKCoordinateRegion cbbRegion;
// CBB LATITUDE N LONGITUDE
CLLocationCoordinate2D center;
center.latitude = CBB_LATITUDE;
center.longitude = CBB_LONGITUDE;
// CBB SPAN
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
cbbRegion.center = center;
cbbRegion.span = span;
// SETTING MAPVIEW
[self.myMapView setRegion:cbbRegion animated:NO];
[self.myMapView setMapType:MKMapTypeStandard];
//[self.myMapView setZoomEnabled:YES];
self.myMapView.showsUserLocation = YES;
}
- (void)viewDidUnload
{
[self setMyMapView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
it is resolved now. my 1st mistake was i did not set map.delegate=self. 2nd mistake was that my internet connection was not working and this i figured by implementing mapViewDidFailLoadingMap:withError method. Thanks... D-eptdeveloper
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.