我使用ARToolkit
sdk作为基于位置的AR,用于显示geolocation
点
相机。我已经为ios实现了这个sdk,我有一个问题是两个gps
个点在同一个方向上相互重叠。如何解决这个问题请帮帮我。
我在AugmentedRealityController.m
方法的updateLocations
类中略有变化。根据距离我调整屏幕上的标签高度,但问题没有解决,如何在两个重叠标记之间做出间隙。
if ([item distanceFromOrigin]>= 50 && [item distanceFromOrigin]<= 100) {
scaleFactor = 1.2;
loc.y = loc.y - 20;
}
else if ([item distanceFromOrigin]>= 100 && [item distanceFromOrigin]<= 150) {
scaleFactor = 0.8;
loc.y = loc.y - 50;
}
else if ([item distanceFromOrigin]>= 150 && [item distanceFromOrigin]<= 200) {
scaleFactor = 0.6;
loc.y = loc.y - 80;
}
else if ([item distanceFromOrigin]>= 200 && [item distanceFromOrigin]<= 300) {
scaleFactor = 0.6;
loc.y = loc.y - 100;
}
else if ([item distanceFromOrigin]>= 300 && [item distanceFromOrigin]<= 400) {
scaleFactor = 0.6;
loc.y = loc.y - 120;
}
else if ([item distanceFromOrigin]>= 400 && [item distanceFromOrigin]<= 500) {
scaleFactor = 0.5;
}
else if ([item distanceFromOrigin]>= 500 && [item distanceFromOrigin]<= 600) {
scaleFactor = 0.5;
}
else if ([item distanceFromOrigin]> 500)
{
scaleFactor = 0.5;
}
[markerView setFrame:CGRectMake(loc.x - width / 2.0, loc.y -[item radialDistance]/100, width, height)];
// [markerView setFrame:CGRectMake(loc.x - width / 2.0, loc.y, width, height)];
[markerView setNeedsDisplay];
}
如果有人知道如何解决这个问题,请帮助我。
答案 0 :(得分:0)
我通过对代码进行一些更改来解决了callout碰撞的问题。
1)在AugmentedRealityViewController
中有updateLocations
方法,进入if
条件并
if (!([markerView superview])) {
[[self displayView] insertSubview:markerView atIndex:1];
[self listSubviewsOfView:markerView]; // retrive the subviews from the markerview which is display on the camera screen...
}
此条件为updatelocation
方法,我调用listSubviewsOfView
方法,该方法用于从subview
重新审核superView
。
(void)listSubviewsOfView:(UIView *)view {
// Get the subviews of the view
NSArray *subviews = [view subviews];
// Return if there are no subviews
if ([subviews count] == 0) return;
for (UIView subview in subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
UIImageView *myLabel = (UIImageView *)subview;
myLabel.clipsToBounds = YES;
if (myLabel.tag == 1)
{
numberOfImageView++;
CGRect rect = myLabel.frame;
rect.origin.y = 0+numberOfImageView50;
myLabel.frame = rect;
}
}
// List the subviews of subview
[self listSubviewsOfView:subview];
}
}
//there is variable numberOfImageView. declare in .h file
int numberOfImageView;
//and do one thing in else condition of the updateLocation Method , set the "numberOfImageView" to zero.
else
if ([markerView superview])
{
[markerView removeFromSuperview];
numberOfImageView =0;
}
然后编译并运行
答案 1 :(得分:0)
在AugmentedRealityViewController的UpdateLocation方法中进行一些更改 您可以计算两个标记视图之间的差异,然后设置标记的值y位置。
for (ARGeoCoordinate *item in [self coordinates]) {
UIView *markerView = [item displayView];
if ([self shouldDisplayCoordinate:item]) {
CGPoint loc = [self pointForCoordinate:item];
CGFloat scaleFactor = SCALE_FACTOR;
if ([self scaleViewsBasedOnDistance])
scaleFactor = scaleFactor - [self minimumScaleFactor]*([item radialDistance] / [self maximumScaleDistance]);
float width = [markerView bounds].size.width * scaleFactor;
float height = [markerView bounds].size.height * scaleFactor;
if ([item distanceFromOrigin]>0) {
float difference = [item distanceFromOrigin]-prevLoc;
if ((difference>0 &&difference<200) || ( difference < 0 && difference>(-200))) {
[markerView setFrame:CGRectMake(loc.x - width / 2.0, loc.y-difference, width, height)];
}
prevLoc = [item distanceFromOrigin];
}
}
else if ([markerView superview])
{
[markerView removeFromSuperview];
}
}
prevLoc是.h文件中的float类型变量声明,并在init方法中初始化为零。
它将管理标记以便y位置。