我的视图控制器中有一个函数,它有一个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];
}
答案 0 :(得分:2)
只需保持设置中心坐标,不要设置区域。
顺便说一下,你确实知道你不需要任何代码,对吧?您可以告诉mapview跟踪设备的当前位置。请参阅我的书中的示例:
http://www.apeth.com/iOSBook/ch34.html#_map_kit_and_current_location