2013-03-29 75 views
0

我在视图控制器中有一个函数,它具有当位置更改时调用的mapkit。我想设置为地图视图,以便以当前位置为中心并在更新时随其移动。更新位置时的地图视图范围更改

它在某种意义上说起作用,即它可以跟踪,但它始终在放大真的很远。如果我缩小了对齐回到它在获取新位置后再次调用更新的位置。

in from params CLLocation *loc 
bool first = TRUE; 
if(first){ 
     first=FALSE; // bit of a bodge...if i set this to false it will track the update possition but not at the desired "zoom" its look far to close. 
     CLLocation *loc = [[CLLocation alloc] initWithLatitude:54.976619 longitude:-1.613118];//newcastle city center. 
     CLLocationDegrees spanLat = 1000; 
     CLLocationDegrees spanLng = 1000; 
     userLocation = MKCoordinateRegionMakeWithDistance(loc.coordinate, spanLat, spanLng); 
     [mapview setRegion:userLocation animated:TRUE]; 
    }else { 
     CLLocationDegrees spanLat = [mapview region].span.latitudeDelta;// keep the originals? DOESN'T WORK!! 
     CLLocationDegrees spanLng = [mapview region].span.longitudeDelta;// 
     userLocation = MKCoordinateRegionMakeWithDistance(loc.coordinate, spanLat, spanLng); 
     [mapview setRegion:userLocation animated:TRUE]; 
    } 

回答

2

只要保持设置中心坐标,不要设置区域。

顺便说一句,你知道你不需要任何代码,对吗?您只需告知地图视图即可跟踪设备的当前位置。以我的书为例:

http://www.apeth.com/iOSBook/ch34.html#_map_kit_and_current_location

+0

很感谢。我确实在视图的第一部分关闭了。但似乎没有工作。在if作品的第二部分设置中心。但我确实需要摆脱,如果这就是为什么我说这是一个闪光点。 – Andrew