开发者

iPhone SDK: How to center map around a particular point?

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[开发者_JS百科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];
}


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;


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];


Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜