MKCoordinateRegion不以正确的方式显示在地图上

时间:2012-02-24 11:53:31

标签: iphone objective-c ios ipad mapkit

我正在使用以下代码在地图MKMapView上缩小。

float zoom=1.5;
MKCoordinateRegion region;
//Set Zoom level using Span
MKCoordinateSpan span;  
region.center=mapView.region.center;
span.latitudeDelta=mapView.region.span.latitudeDelta *zoom;
span.longitudeDelta=mapView.region.span.longitudeDelta *zoom;
region.span=span;
[mapView setRegion:region animated:TRUE];

但是在zoom = 1.1,zoom = 1.3或zoom = 1.5的情况下,地图在所有3种情况下都显示相同的regian。该区域与zoom = 2时的区域相同。

如何显示地图,以便在每种情况下都显示正确的区域?

2 个答案:

答案 0 :(得分:1)

试试这个....

region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 

您可以将span.longitudeDeltaspan.latitudeDelta设置为您想要放大或缩小的程度... 并初始化MKCoordinateRegion ..

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } } 

将委托设置为mapView

[mapView setDelegate:self];

答案 1 :(得分:1)

试试这个

MKCoordinateSpan span; 
//You can set span for how much Zoom to be display
span.latitudeDelta=.005;
span.longitudeDelta=.005;

//set Region to be display on MKMapView
MKCoordinateRegion cordinateRegion;
cordinateRegion.center=latAndLongLocation.coordinate;
//latAndLongLocation coordinates to be display 
cordinateRegion.span=span;

[mapView setRegion:cordinateRegion animated:YES];
//mapView MkMapView

一定会有用。