Ios 不更新位置
我正在使用github的Ios 不更新位置,ios,objective-c,mkmapview,mkannotation,Ios,Objective C,Mkmapview,Mkannotation,我正在使用github的HGMovingAnnotation和HGMovingAnnotationViewcode在MKmap上设置MKAnnotation的动画。当我从HG项目运行示例项目时,一切都很好 我已经更改了原始的HG项目,允许我手动将新坐标推送到HGMapPath,然后将注释移动到我想要的位置 我放置了一个按钮,用于测试,运行手动过程,一切正常。注释在屏幕上移动。问题是,当我现在尝试使用livesocket.io连接中的数据调用此手动方法时,映射注释不会移动 另外,当贴图第一次加载时
HGMovingAnnotation
和HGMovingAnnotationView
code在MKmap
上设置MKAnnotation
的动画。当我从HG项目运行示例项目时,一切都很好
我已经更改了原始的HG项目,允许我手动将新坐标推送到HGMapPath
,然后将注释移动到我想要的位置
我放置了一个按钮,用于测试,运行手动过程,一切正常。注释在屏幕上移动。问题是,当我现在尝试使用livesocket.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)];
}
}
}
-(iAction)testMoveBtnPressed:(id)发送方{
//TODO:移动x和y
DLog(@“=========================测试移动按钮已按下=======================”);
NSLog(@“);
int randn=(random()%15)+15;
浮动pscale=(浮动)随机数/10000;
双lat=39.9813855+pscale;
双lng=-75.1502155+pscale;
for(self.mapView.annotations中的id注释){
MKAnnotationView*anView=[self.mapviewforannotation:annotation];
如果(![annotation isKindOfClass:[PhoneAnnotation class]]){
//进程注释视图
[((HGMovingAnnotation*)注释)轨道位置:CLLocationCoordination2dMake(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)];
}
}
}
{
//TODO:将对象移动到新位置
double doubleLat=[lat doubleValue];
double doubleLng=[lng doubleValue];
//NSLog(@“----------Jason它是----------正在传入的纬度是%f”,doubleLat);
//NSLog(@“---------------Jason它是----------传入的经度是%f”,doubleLng);
//
//[自行移动Assignedambo对象轨道到新位置:CLLocationCoordination2DMAKE(双平面,双平面)];
for(self.mapView.annotations中的id注释){
MKAnnotationView*anView=[self.mapviewforannotation:annotation];
如果(![annotation isKindOfClass:[PhoneAnnotation class]]){
//进程注释视图
[((HGMovingAnnotation*)注释)轨迹新位置:CLLocationCoordination2DMAKE(doubleLat,doubleLng)];
}
}
}
问题在于HG库,尽管所述的工作方式无法正常工作,除非您使用路径,否则如果您没有创建附加坐标的注释,它就不会正常工作。您可以发布代码吗?否则我们帮不了你。