0

ビューコントローラーに、場所が変更されたときに呼び出されるマップキットを備えた関数があります。現在の場所を中心にして、更新されると移動するようにマップ ビューに設定したいと思います。

ある意味では機能します。つまり、追跡しますが、常に非常にズームインされます。ズームアウトすると、新しい場所を取得した後に更新を再度呼び出したときの場所に戻ります。

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

1 に答える 1

2

中心座標を設定し続け、領域を設定しないでください。

ところで、そのコードはまったく必要ないことを知っていますよね? デバイスの現在の位置を追跡するように mapview に指示するだけです。例については、私の本を参照してください。

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

于 2013-03-29T22:29:24.323 に答える