【发布时间】:2012-06-08 21:19:48
【问题描述】:
我尝试了很多,但无法为我的应用程序制作 Qibla 指南针。我无法理解我在做什么。我需要完美运行的朝拜指南针。
【问题讨论】:
-
你需要更具体。
-
你想编程吗?你有什么问题?你试过什么?
标签: android compass-geolocation
我尝试了很多,但无法为我的应用程序制作 Qibla 指南针。我无法理解我在做什么。我需要完美运行的朝拜指南针。
【问题讨论】:
标签: android compass-geolocation
您知道麦加的位置,并且您知道用户的当前位置(如果您有 GPS 或其他位置提供商)。方位由这个公式给出,纬度和经度应该以弧度为单位。
float lonDelta = (lon2 - lon1);
float y = Math.sin(lonDelta) * Math.cos(lat2);
float x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
float brng = Math.atan2(y, x).toDeg();
brng 是以度为单位的方向。
您还可以探索 Location.bearingTo() 方法,see here。
【讨论】:
Cannot invoke toDeg() on the primitive type double
float brng = (float) Math.toDegrees(Math.atan2(y, x));