繁体   English   中英

Android imageView定位算法

[英]Algorithm for positioning with Android imageView

我正在开发Android应用程序,以便使用API​​的指南针,GPS和摄像头在大学中提供位置信息。

还可以基于上述API获取一些重要数据。 这不是Android或Java的内置功能,需要某种算法。 我需要进行计算,得出的位置(x)是当移动用户面对的方向时,气球应该出现在屏幕上。

为了进行计算,我已经有了以下数据:

  • 度:用户指示手机的方向(度)(使用指南针获得);
  • grausParaDestino:方向(度),气球应该在屏幕的中心(通过GPS点获得的计算结果);
  • width:屏幕的宽度;

我们知道,用户在其轴上总共旋转了360度。

我尝试了下面的演算,但不正确。

int position = Math.round (((width * grausParaDestino) / 360) + degrees);

昨天下午我花了很多时间尝试解决这种计算问题,但是没有成功。 如果他们能给我一些帮助,我将不胜感激。

if( grausParaDestino < 0 ){
    grausParaDestino = grausParaDestino + 360;
}else if( grausParaDestino > 360 ){
    grausParaDestino = grausParaDestino - 360;
}

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

if( anlgeOfView < 1 ){
    anlgeOfView = mPreview.getCameraAngleOfView();
}

int larguraDaTela;
if( width > height ){
    larguraDaTela = width;
}else{
    larguraDaTela = height;
}

double linhaImaginaria = ( larguraDaTela * 360 ) / anlgeOfView;

double posicaoDestinoLinhaImaginaria = ( grausParaDestino * linhaImaginaria ) / 360;
double posicaoPontoAtualLinhaImaginaria = ( graus * linhaImaginaria ) / 360;

double posicaoBalao = posicaoPontoAtualLinhaImaginaria - posicaoDestinoLinhaImaginaria;

double position = Math.round( ( width / 2 ) - posicaoBalao );

layoutParams layoutParams=new LayoutParams(width, height);
layoutParams.height = 50;
layoutParams.width = 50;
layoutParams.setMargins( (int)position, 50, 0, 0);

ImageView balao = (ImageView)findViewById(R.id.balao);
balao.setLayoutParams(layoutParams);

通过此代码,我将球杆定位在了幕布上。 感谢您的所有回复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM