我的雷达视图遇到了一些问题,我非常接近解决方案,但我不知道出了什么问题。为此,我创建了一个类radarView。问题是,当我浏览我周围的位置时,由几个白点表示的位置都分散在雷达视图的对角线上,从左上角到右下角。
以下是我根据位置方位角和我自己方位角之间的差异计算点坐标的方法:
-(float)calculateDelta:(double*)currentAzimuth withLoc:(ARGeoLocation *)location{
double deltaAzimuth;
deltaAzimuth = ABS(location.locationAzimuth - *currentAzimuth);
if (*currentAzimuth < 0.0)
*currentAzimuth = 2*M_PI + *currentAzimuth;
else if (*currentAzimuth > 2*M_PI)
*currentAzimuth = *currentAzimuth - 2*M_PI;
deltaAzimuth = location.locationAzimuth - *currentAzimuth;
if (deltaAzimuth < 0.0)
deltaAzimuth = 2*M_PI + deltaAzimuth;
else if (deltaAzimuth > 2*M_PI)
deltaAzimuth = deltaAzimuth - 2*M_PI;
return deltaAzimuth;
}
-(float)calculateXPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;
if(0<=angle<=90)
return self.center.x + sin(angle)*dpx;
else if(90<angle<=180)
return self.center.x + cos(angle-90)*dpx;
else if(180<angle<=270)
return self.center.x - cos(270-angle)*dpx;
else if(270<angle<360)
return self.center.x - sin(360-angle)*dpx;
}
-(float)calculateYPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;
if(0<=angle<=90)
return self.center.y - cos(angle)*dpx;
else if(90<angle<=180)
return self.center.y + sin(angle-90)*dpx;
else if(180<angle<=270)
return self.center.y + sin(270-angle)*dpx;
else if(270<angle<360)
return self.center.y - cos(360-angle)*dpx;
}
上面的 dpx 表示该位置与雷达视图中心的距离(以像素为单位)。最后用这些数据更新雷达上的点,实际上 UIView 存储在radarView类的数组“plots”中:
-(void)updateRadar:(double*)currentAzimuth andRange:(float)range{
float x,y;
int i=0;
float deltaAz;
for(ARGeoLocation *loc in coordinates){
deltaAz = [self calculateDelta:currentAzimuth withLoc:loc andRange:range];
x = [self calculateXPointWithLoc:loc andDelta:deltaAz];
// NSLog(@"x: %f",x);
y = [self calculateXPointWithLoc:loc andDelta:deltaAz];
// NSLog(@"y: %f",y);
[[plots objectAtIndex:i] setFrame:CGRectMake(x, y, DIAMETER_PLOT, DIAMETER_PLOT)];
i++;
}
}
有没有人已经体验过创建雷达视图?