0

をアニメーション化するために githubのHGMovingAnnotationandコードを使用しています。HG プロジェクトからサンプル プロジェクトを実行すると、すべて正常に動作します。HGMovingAnnotationViewMKAnnotationMKmap

元の HG プロジェクトを変更して、手動で新しい座標を にプッシュしHGMapPath、注釈を必要な場所に移動できるようにしました。

テスト用に、手動プロセスを実行するためのボタンを配置しましたが、すべて正常に動作します。注釈が画面上を移動します。問題は、ライブ socket.io 接続からのデータを使用してこの手動メソッドを呼び出そうとすると、マップ アノテーションが移動しないことです。

また、マップが最初にロードされるとき、マップを少し移動するまで注釈は表示されません。手動で注釈を移動する場合も同じです。マップをズームするまで、データのストリームからの移動は表示されません。しかし、io ストリームを避けてプッシュ ボタンを使用すると、マップをズームまたはパンしなくても注釈が移動しますか?

ビュー注釈の配置

if(doubleLat && doubleLng) {

            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(doubleLat, doubleLng);

            //Create path object
            self.assignedAmbPath = [[HGMapPath alloc] initWithCoordinate:coordinate];

            HGMovingAnnotation *movingObject = [[HGMovingAnnotation alloc] initWithMapPath:self.assignedAmbPath];

            self.movingAssignedAmbObject = movingObject;


            // add the annotation to the map
            [self.mapView addAnnotation:movingObject];


            // zoom the map around the moving object
            MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
            MKCoordinateRegion region = MKCoordinateRegionMake(MKCoordinateForMapPoint(self.movingAssignedAmbObject.currentLocation), span);
            [self.mapView setRegion:region animated:YES];

            // start moving the object
            [movingObject start];

        }

動作するコード

 - (IBAction)testMoveBtnPressed:(id)sender {
//TODO: move x and y
DLog(@"============== Test move button was pressed ================ ");
NSLog(@"");

int randn = (random() % 15)+15;
float pscale = (float)randn / 10000;

double lat = 39.9813855 + pscale;
double lng = -75.1502155 + pscale;

for (id<MKAnnotation> annotation in self.mapView.annotations){
    MKAnnotationView* anView = [self.mapView viewForAnnotation: annotation];
    if (![annotation isKindOfClass:[PhoneAnnotation class]]){
        // Process annotation view
        [((HGMovingAnnotation *)annotation) trackToNewPosition:CLLocationCoordinate2DMake(lat, lng)];
    }
  }
}

動作しないコード

{

                    //TODO: move thing to new location
                    double doubleLat = [lat doubleValue];
                    double doubleLng = [lng doubleValue];
 //                        NSLog(@"--------------- Jason it is -------------  Latitude   being passed in is %f", doubleLat);
//                        NSLog(@"--------------- Jason it is -------------  Longitude being passed in is %f", doubleLng);
//                        
//                        [self.movingAssignedAmbObject trackToNewPosition:CLLocationCoordinate2DMake(doubleLat, doubleLng)];




                    for (id<MKAnnotation> annotation in self.mapView.annotations){
                        MKAnnotationView* anView = [self.mapView viewForAnnotation: annotation];
                        if (![annotation isKindOfClass:[PhoneAnnotation class]]){
                            // Process annotation view
                            [((HGMovingAnnotation *)annotation) trackToNewPosition:CLLocationCoordinate2DMake(doubleLat, doubleLng)];

                        }
                    }


                }
4

1 に答える 1