[英]Location getBearing is returning negative values
我正在嘗試從電話位置獲取實時方位。
從GPS可以直接獲取location.getBearing()
方位。 但是,如果我們使用的是蜂窩網絡,則無法獲取方位角,因此我正在嘗試使用以下方法從保存的舊位置和當前位置計算方位角
heading = mLocation.bearingTo(location);
mLocation
是舊位置, location
是新位置。 但是,它的某些值是負面的。
http://developer.android.com/reference/android/location/Location.html
清楚地表明值應該在0到360之間,這是怎么回事。
如果您向東移動,則方位角為90度;如果向南移動,則方位角為+180或-180;如果向西移動,則方位角為-90度。
嘗試使用以下行
int azimut = (int) Math.round(Math.toDegrees(orientation[0]));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.