iPhone mapview区域缩放不正常

时间:2011-04-19 01:17:23

标签: iphone map

这是我的代码:

CLLocationCoordinate2D location;
location.latitude = 50;
location.longitude = -50;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 5, 5);

region.center=location;
[mapView setShowsUserLocation:TRUE];
[mapView setDelegate:self];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self setView:mapView];

它会放大,但放大太远。 所以如果我改成它:

    CLLocationCoordinate2D location;
location.latitude = 50;
location.longitude = -50;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 200, 200);

region.center=location;
[mapView setShowsUserLocation:TRUE];
[mapView setDelegate:self];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self setView:mapView];

它将一直缩小。有什么我想念的吗?

2 个答案:

答案 0 :(得分:1)

这是因为它在执行中过早地调用了该方法。我添加了一个viewWillLoad,它将在加载后调用,然后一切正常。谢谢你的帮助。

答案 1 :(得分:0)

对于MKCoordinateRegionMakeWithDistance的第2和第3个参数,5到200之间的数字不会使区域放大中间量吗? docs表示这些参数是每个方向的距离,包括在该区域内。