0
我正在使用HGMovingAnnotation
和HGMovingAnnotationView
关闭github上的的动画MKmap
。当我从HG项目运行示例项目时,一切正常。MKAnnotation没有更新位置
我已经完成了原始HG项目,允许我手动将新坐标推送到HGMapPath
,然后将注释移动到我想要的位置。
我已经放置了一个按钮,进行测试,运行手动过程,一切正常。注释在屏幕上移动。问题是,当我尝试使用实时socket.io连接的数据调用此手动方法时,映射注释将不会移动。
此外,当地图第一次加载注释将不会显示,直到我移动地图一点点。对于手动移动注释来说,同样的事情,它不会显示数据流中的移动,直到我缩放地图。但是如果我按下按钮的方式,避开io流,注释会移动而无需缩放或平移地图?
将该View说明一
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];
}
CODE的作品
- (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)];
}
}
}
CODE不起作用
{
//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)];
}
}
}
你可以发布你的代码吗?否则我们将无法为您提供帮助。 – jszumski