【发布时间】:2015-07-01 16:52:32
【问题描述】:
我需要将图像箭头旋转到特定位置。这是我当前的代码:
public void onSensorChanged(SensorEvent event) {
float azimuth = event.values[0];
Location currentLoc = getHelper().getCurrentLocation();
if(currentLoc == null || cardinal == null || cardinal.getLocation() == null) {
return;
}
azimuth = (float) Math.toDegrees(azimuth);
GeomagneticField geoField = new GeomagneticField(
(float) currentLoc.getLatitude(),
(float) currentLoc.getLongitude(),
(float) currentLoc.getAltitude(),
System.currentTimeMillis());
azimuth += geoField.getDeclination(); // converts magnetic north into true north
float bearing = currentLoc.bearingTo(cardinal.getLocation()); // (it's already in degrees)
float direction = azimuth - bearing;
direction = -direction;
if(compass != null) {
compass.setDirection(direction);
}
}
这是我的自定义图像视图:
public void onDraw(Canvas canvas) { //
int height = this.getHeight(); //
int width = this.getWidth();
canvas.rotate(direction, width / 2, height / 2); //
super.onDraw(canvas); //
}
这是我正在使用的箭头图像:
此代码根本不起作用。谁能指出我做错了什么?
【问题讨论】:
标签: android location latitude-longitude compass