特定の場所を指すために、方向センサーを使用する矢印を実装しようとしています。Google プレイスは、検索した場所ごとに ListView にこの矢印を実装します。
方位角を取得できましたが、場所が指定されているため、必要な角度を計算する方法がわかりません。さらに、真北と磁北から変換する必要があります。そのような実装の例はありますか?
前もって感謝します。
特定の場所を指すために、方向センサーを使用する矢印を実装しようとしています。Google プレイスは、検索した場所ごとに ListView にこの矢印を実装します。
方位角を取得できましたが、場所が指定されているため、必要な角度を計算する方法がわかりません。さらに、真北と磁北から変換する必要があります。そのような実装の例はありますか?
前もって感謝します。
私はそれを解決しました。
float azimuth = // get azimuth from the orientation sensor (it's quite simple)
Location currentLoc = // get location from GPS or network
// convert radians to degrees
azimuth = Math.toDegrees(azimuth);
GeomagneticField geoField = new GeomagneticField(
(float) currentLoc.getLatitude(),
(float) currentLoc.getLongitude(),
(float) currentLoc.getAltitude(),
System.currentTimeMillis());
azimuth += geoField.getDeclination(); // converts magnetic north to true north
float bearing = currentLoc.bearingTo(target); // (it's already in degrees)
float direction = azimuth - bearing;
方向を示す矢印などを描画する場合は、canvas.rotate(-direction) を使用します。キャンバスの回転は反時計回りであるため、負の引数を渡します。