2016-07-19 3 views
0

this one,thisおよびthis oneのように、stackOverflowでこれに関するいくつかの質問が見つかりました。最後に実際に働いたのですが、問題はをMapKitで使用しています。これは(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeadingを意味します。MKMapViewの中心を移動して、デフォルトの位置アイコンが下部の中心に行くようにする方法

MKCoordinateRegion oldRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 800.0f, 200.0f)]; 
    CLLocationCoordinate2D centerPointOfOldRegion = oldRegion.center; 

    //Create a new center point (I added a quarter of oldRegion's latitudinal span) 
    CLLocationCoordinate2D centerPointOfNewRegion = CLLocationCoordinate2DMake(centerPointOfOldRegion.latitude + oldRegion.span.latitudeDelta/5.0, centerPointOfOldRegion.longitude); 

    //Create a new region with the new center point (same span as oldRegion) 
    MKCoordinateRegion newRegion = MKCoordinateRegionMake(centerPointOfNewRegion, oldRegion.span); 

    //Set the mapView's region 
    [_mapView setRegion:newRegion animated:NO]; 

私は自分の携帯電話を移動すると、それが成功したが更新され、accelometerはそれがnewRegionとoldRegionの間にけいれん効果を開始してアクセスされる:SOそれを今の問題は、私は、このソリューションを適用したとき。どのような提案?

UPDATE
私は私がuserLocation annotationのデフォルトの画像を変更でき、これは私はこれがうまくいくかもしれないということや、その中心を設定する方法をここにそうmyAnnotaton.centerのように任意のアイデアを設定することができますプロパティを持っていました。この方法を見つけましたか?

- (MKAnnotationView *)mapView:(MKMapView *)mapView 
      viewForAnnotation:(id<MKAnnotation>)annotation { 


    if (annotation==(mapView.userLocation)) { 
     MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init]; 

     myAnotation.image = [UIImage imageNamed:@"marker"]; 
     myAnotation.frame = CGRectMake(0, 0, 100, 100); 

     return myAnotation; 
    } 
    else 
    { 
    return nil; 
    } 
} 
+0

、それに応じて回転する[_mapView setRegion:newRegionアニメーション:NO]を。それで、それは躍動的ではありません。 – sanman

+0

@サンマンそれは働いていない...今は、アプリは、以前は自動的にズームしていたようにズームしている宿題がつまっています...今それは時間を突破し、クラッシュ...あなたが特定のコードの一部。 –

答えて

1

デフォルトアノテーションを上書きするデリゲートメソッドを追加する必要があります。

- (MKAnnotationView *)mapView:(MKMapView *)mapView 
      viewForAnnotation:(id<MKAnnotation>)annotation { 


    if (annotation==(mapView.userLocation)) { 
     MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init]; 

     myAnotation.image = self.userPointImage.image; //give any image here 
     myAnotation.centerOffset = CGPointMake(0, 250); 

     return myAnotation; 
    } 
    else 
    { 
    return nil; 
    } 
} 

centerOffset底に注釈を設定し、マップはYESにアニメーション設定してみてください

関連する問題