Android 有GPS定位和我的GPS定位¿;如何计算从我的位置到该位置的方向(从北0-360º;)?
我试着用BearingTo(),但我不知道如何使用它。myLocation.bearingTo(BuildingLocation)如果我面对建筑和北向,则为0º;如果我面对建筑和东向,则为90º;如果我面对建筑和南向,则为-180º。那么bearingTo就不能满足我的需要了 我需要这样做,因为我需要计算手机摄像头何时面对对象…请尝试以下链接: 编辑——这将是一个示例,使用位置或以其他方式获取long/latAndroid 有GPS定位和我的GPS定位¿;如何计算从我的位置到该位置的方向(从北0-360º;)?,android,gps,compass-geolocation,Android,Gps,Compass Geolocation,我试着用BearingTo(),但我不知道如何使用它。myLocation.bearingTo(BuildingLocation)如果我面对建筑和北向,则为0º;如果我面对建筑和东向,则为90º;如果我面对建筑和南向,则为-180º。那么bearingTo就不能满足我的需要了 我需要这样做,因为我需要计算手机摄像头何时面对对象…请尝试以下链接: 编辑——这将是一个示例,使用位置或以其他方式获取long/lat Location destination; Location fro
Location destination;
Location from;
double dLon = Math.abs(destination.getLongitude()-from.getLongitude()); //Delta Longitude
double y = Math.sin(dLon) * Math.cos(destination.getLatitude());
double x = Math.cos(from.getLatitude())*Math.sin(destination.getLatitude()) -
Math.sin(from.getLatitude())*Math.cos(destination.getLatitude())*Math.cos(dLon);
double brng = Math.atan2(y, x);
double brngdegrees = Math.toDegrees(brng);
请尝试以下链接:
编辑——这将是一个示例,使用位置或以其他方式获取long/lat
Location destination;
Location from;
double dLon = Math.abs(destination.getLongitude()-from.getLongitude()); //Delta Longitude
double y = Math.sin(dLon) * Math.cos(destination.getLatitude());
double x = Math.cos(from.getLatitude())*Math.sin(destination.getLatitude()) -
Math.sin(from.getLatitude())*Math.cos(destination.getLatitude())*Math.cos(dLon);
double brng = Math.atan2(y, x);
double brngdegrees = Math.toDegrees(brng);
很好的链接,但我不明白怎么做,解释对我来说太复杂了。我不知道如何做我需要的:S.有人能帮我做吗?链接不错,但我不知道如何做,解释对我来说太复杂了。我不知道该怎么做我需要的:S.有人能帮我做吗?