根据目前的步行方向的Andr​​oid谷歌地图旋转,地图

问题描述:

我有地图谷歌的android应用。
谁能告诉我,我们如何旋转,根据用户当前的方向行走地图?我已经阅读了大量的信息,但仍然是一个利特尔有点糊涂了。

I have an android application with a map of google. Can anybody tell me how we rotate the map according user current direction walking? I have read a lot of information but still a litle bit confused.

感谢

您可以通过比较两个点计算轴承。你说,你的用户将走,这样应该不会太难相互拿到两分的距离分开。

You can calculate bearing by comparing two points. You said that your user will be walking so that shouldn't be too hard to get two points a distance apart from each other.

当你有两个点做一些数学像这样

When you have the two points do some math like so

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 //

这是我们的转换功能

These are our conversion functions

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地图。

Once you have the bearing you can pass it to your map using the CameraUpdateFactory.

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