我正在开发一个浮动操纵杆应用程序,该应用程序获取用户的当前位置,当用户点击按钮纬度时,经度值将被更改。然后,此更改的位置将设置为当前位置,依此类推。左,右,下按钮相同。
当我第一次点击任何按钮时,它改变了坐标值,我的位置在谷歌地图中发生了变化,但问题是如果我按任何其他按钮我再次移回原来的位置。我不知道为什么会这样。
这是我的代码:
double i=0.000100;
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
mInview = (RelativeLayout)inflater.inflate(R.layout.myarrow, null, false);
RelativeLayout.LayoutParams layoutParameteres = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
mInview.setLayoutParams(layoutParameteres);
final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
600, 400, WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
wm.addView(mInview, parameters);
mInview.setOnTouchListener(new View.OnTouchListener() {
WindowManager.LayoutParams updatedParameters = parameters;
@Override
public boolean onTouch(View v, MotionEvent event) {
}
});
mInview.findViewById(R.id.left).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
gps = new Gpsmap(FloatingWindow.this);
if(gps.canGetLocation()) {
latitude = gps.getLatitude() ;
longitude = gps.getLongitude()-i;
i=i-0.000050;
mockGPS = new MockLocationProvider(LocationManager.GPS_PROVIDER, FloatingWindow.this);
mockGPS.pushLocation(latitude, longitude,50.0, 50);
} else {
gps.showSettingsAlert();
}
}
});
mInview.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
gps = new Gpsmap(FloatingWindow.this);
if(gps.canGetLocation()) {
latitude = gps.getLatitude()-i;
longitude = gps.getLongitude();
i=i-0.000050;
mockGPS = new MockLocationProvider(LocationManager.GPS_PROVIDER, FloatingWindow.this);
mockGPS.pushLocation(latitude, longitude,50.0, 50);
} else {
gps.showSettingsAlert();
}
}
});
mInview.findViewById(R.id.right).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
gps = new Gpsmap(FloatingWindow.this);
if(gps.canGetLocation()) {
latitude = gps.getLatitude();
longitude = gps.getLongitude()+i;
i=i+0.0000010;
mockGPS = new MockLocationProvider(LocationManager.GPS_PROVIDER, FloatingWindow.this);
mockGPS.pushLocation(latitude, longitude,50.0, 50);
} else {
gps.showSettingsAlert();
}
}
});
mInview.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
gps = new Gpsmap(FloatingWindow.this);
if(gps.canGetLocation()) {
latitude = gps.getLatitude()+i;
longitude = gps.getLongitude();
i=i+0.000010;
mockGPS = new MockLocationProvider(LocationManager.GPS_PROVIDER, FloatingWindow.this);
mockGPS.pushLocation(latitude, longitude,50.0, 50);
} else {
gps.showSettingsAlert();
}
}
});