rotate map according current walk direction android google maps

时光毁灭记忆、已成空白 提交于 2019-12-11 09:43:51

问题


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.

Thanks


回答1:


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;
 }

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)));


来源:https://stackoverflow.com/questions/26303370/rotate-map-according-current-walk-direction-android-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!