tags:

views:

91

answers:

3

New to MapKit. Having problems centering map around a specified point. Here is the code. Not sure why this is not working. We are expecting to see a map centered around Cincinnati, OH. What we are seeing is the default google map of the world.

Any help appreciated.

/ Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [super viewDidLoad];

    CLLocationCoordinate2D mapCoords[2];
    mapCoords[0].latitude = 39.144057;
    mapCoords[0].latitude = -84.505484;
    mapCoords[1].latitude = 39.142984;
    mapCoords[1].latitude = -84.502534;

    MKCoordinateSpan span;
    span.latitudeDelta = 0.2;
    span.longitudeDelta = 0.2;

    MKCoordinateRegion region;
    region.center = mapCoords[0];
    region.span = span;

    [mapView setRegion:region animated:YES];
}
A: 

Change:

mapCoords[0].latitude = 39.144057;
mapCoords[0].latitude = -84.505484;
mapCoords[1].latitude = 39.142984;
mapCoords[1].latitude = -84.502534;

To:

mapCoords[0].latitude = 39.144057;
mapCoords[0].longitude = -84.505484;
mapCoords[1].latitude = 39.142984;
mapCoords[1].longitude = -84.502534;
Felix Khazin
What is the difference? They look the same. I must be missing something?
Please disregard the previous comment, I see the typo. However, I changed it and I am still unable to center a region around a point. I am not sure why? [super viewDidLoad]; CLLocationCoordinate2D mapCoords[2]; mapCoords[0].latitude = 39.144057; mapCoords[0].longitude = -84.505484; mapCoords[1].latitude = 39.142984; mapCoords[1].longitude = -84.502534; MKCoordinateSpan span; span.latitudeDelta = 0.005; span.longitudeDelta = 0.005; MKCoordinateRegion region; region.center = mapCoords[0]; region.span = span; [mapView setRegion:region animated:YES];
A: 

I do this in my code and it works fine:

MKCoordinateRegion region;
MKCoordinateSpan span;

span.latitudeDelta=0.2;
span.longitudeDelta=0.2; 

CLLocationCoordinate2D location;
location.latitude = 39.144057;
location.longitude = -84.505484;

region.span=span;
region.center=location;

[mv setRegion:region animated:TRUE];
[mv regionThatFits:region];
Felix Khazin
A: 

The problem was a combination of the typos above and IB wiring problem.