【问题标题】:rotate map according current walk direction android google maps根据当前步行方向旋转地图 android google maps
【发布时间】:2014-12-05 20:33:15
【问题描述】:

我有一个带有谷歌地图的安卓应用程序。 谁能告诉我我们如何根据用户当前的行走方向旋转地图?我已经阅读了很多信息,但仍然有点困惑。

谢谢

【问题讨论】:

  • 您想研究方向传感器……可能还有它们的局限性。
  • 可能重复 thisthis

标签: android google-maps android-sensors


【解决方案1】:

您可以通过比较两点来计算方位。你说你的用户会走路,所以两个点之间的距离应该不会太难。

当你有两点时,像这样做一些数学运算

lon1 = degToRad(lon1);
lon2 = degToRad(lon2);
lat1 = degToRad(lat1);
lat2 = degToRad(lat2);

double a = Math.Sin(lon2 - lon1) * Math.Cos(lat2);
double b = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1);
double c = radToDeg(Math.Atan2(a, b)); // c is our bearing //

这些是我们的转换函数

public static double degToRad(double deg){
    return deg * Math.PI / 180.0;
}
public static double radToDeg(double rad){
    rad = rad * (180.0 / Math.PI);
    if (rad < 0) rad = 360.0 + rad;
    return rad;
 }

获得方位后,您可以使用 CameraUpdateFactory 将其传递到地图。

map.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(LatLng, zoom, tilt, bearing)));

【讨论】:

  • 你的函数是这样的:'float targetBearing = currentLocation.bearingTo(endingLocation)'?
猜你喜欢
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多