根据目前的步行方向的Andr​​oid谷歌地图旋转,地图 [英] rotate map according current walk direction android google maps

查看:252
本文介绍了根据目前的步行方向的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)));

这篇关于根据目前的步行方向的Andr​​oid谷歌地图旋转,地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆